Pokaż
Ignoruj:
Data:
2009-10-15 15:34:49 (17 years ago)
Autor:
marek
Opis:

re #195 - merged with latest trunk

Lokalizacja:
branches/Emisje
Pliki:
2 zmodyfikowane

Legenda:

Bez zmian
Dodane
Usunięte
  • branches/Emisje

    • Property svn:mergeinfo
      •  

        old new  
        22/branches/ReklamaReorganizacja:568-731 
        33/tags/BazaReklam_1.1.28:831 
        4 /trunk:774-837 
         4/trunk:774-852 
  • branches/Emisje/Wierszowki/Wierszowki.Web/Controllers/ReportController.cs

    r838 r853  
    88using Wierszowki.Core.Linq; 
    99using Wierszowki.Models; 
     10using System.Globalization; 
    1011 
    1112namespace Wierszowki.Controllers 
     
    3536 
    3637            var viewData = new ReportViewData 
    37                                { 
    38                                    Authors = _context.GetAuthors().OrderBy(a => a.FullName).ToList(), 
    39                                    EmploymentTypeList =  new SelectList(_context.GetEmploymentTypes().ToList(),"Id","Name"), 
    40                                    UserList = new SelectList(_context.GetUsers().OrderBy(u => u.FirstName).ToList(),"Id","FullName") 
    41                                }; 
     38            { 
     39                Authors = _context.GetAuthors().OrderBy(a => a.FullName).ToList(), 
     40                EmploymentTypeList =  new SelectList(_context.GetEmploymentTypes().ToList(),"Id","Name"), 
     41                UserList = new SelectList(_context.GetUsers().OrderBy(u => u.FullName).ToList(),"Id","FullName") 
     42            }; 
    4243            return View(viewData); 
    4344        } 
     
    4546        public ActionResult All(int year, int month, int user) 
    4647        { 
    47             var items = _repository.Find(m => m.Date.Month == month && m.Date.Year == year && m.CreatedBy == user) 
     48            var allViewData = new AllViewData(); 
     49            string error = ""; 
     50            string naglowek = ""; 
     51             
     52            if (user <= 0) 
     53            { 
     54                error = "Nie mo¿na wyœwietliæ wierszówek. Spróbuj jeszcze raz. "; 
     55                allViewData = InitAllViewData("", error, null, null); 
     56                return View("Error",allViewData); 
     57            } 
     58            var name = ""; 
     59            var items = new List<MagazineItem>(); 
     60            if (user > 0) 
     61            { 
     62                var u = _context.GetUserById(user); 
     63                if (u != null) 
     64                { 
     65                    name = u.FullName; 
     66                    items = _repository.Find(m => m.Date.Month == month && m.Date.Year == year && m.CreatedBy == user) 
    4867                                   .OrderByDescending(m => m.UpdatedOn).ToList(); 
    49             return View(items); 
     68 
     69                    if (items.Count <= 0) 
     70                    { 
     71                        error = "Brak wierszówek dla tego u¿ytkownika."; 
     72                        allViewData = InitAllViewData("", error, null, null); 
     73                        return View("Error", allViewData); 
     74                    } 
     75                } 
     76                else 
     77                { 
     78                    //U¿ytkownik bo taki nie istnieje  
     79                    error = "Nie mo¿na wyswietliæ wierszówek, gdy¿ u¿ytkownik nie istnieje. "; 
     80                    allViewData = InitAllViewData("", error, null, null); 
     81                    return View("Error", allViewData);    
     82                } 
     83                DateTime dat = new DateTime(1, 1, 1); 
     84                dat = dat.AddYears(year-1); 
     85                dat = dat.AddMonths(month-1); 
     86                
     87                naglowek = "<div class='st1'>Wierszówki z " + dat.ToString("MM/yyyy", CultureInfo.CreateSpecificCulture("en-US")) + "</div>"; 
     88                if ( name != "") 
     89                { 
     90                    naglowek += "<div class='st1'>Wprowadzaj¹cy: <span>" + name + "</span></div>"; 
     91                } 
     92            } 
     93            Info inf = new Info(); 
     94            inf.powrot = "2"; 
     95            inf.month = month; 
     96            inf.year = year; 
     97            inf.user_id = user; 
     98 
     99            allViewData = InitAllViewData(naglowek, error, inf, items); 
     100            return View("All", allViewData);  
    50101        } 
    51102 
    52103        public ActionResult ToPrice() 
    53104        { 
     105            string naglowek = "Wierszówki do wyceny"; 
     106            string  error = ""; 
     107            var allViewData = new AllViewData(); 
     108            Info inf = new Info(); 
     109            inf.powrot = "1"; 
    54110            var items = _repository.Find(m => m.Price <= 0).ToList(); 
    55             return View("All", items); 
     111            if ( items.Count <= 0  ) 
     112            { 
     113                error = "Brak wierszówek do wyceny."; 
     114                allViewData = InitAllViewData(naglowek, error, null, null); 
     115                return View("Error", allViewData);   
     116            } 
     117            allViewData = InitAllViewData(naglowek, "", inf, items); 
     118            return View("All", allViewData); 
    56119        } 
    57120 
     
    69132             
    70133            var viewData = new AuthorCardViewData 
    71                                { 
    72                                    FullName = magazineItems[0].Author.FullName, 
    73                                    Date = magazineItems[0].Date, 
    74                                    MagazineItems = new Dictionary<string, List<MagazineItem>>() 
    75                                }; 
     134            { 
     135                FullName = magazineItems[0].Author.FullName, 
     136                Date = magazineItems[0].Date, 
     137                MagazineItems = new Dictionary<string, List<MagazineItem>>() 
     138            }; 
    76139            foreach (var magazineItem in magazineItems) 
    77140            { 
     
    123186            return View("AuthorsByMagazines", viewData); 
    124187        } 
     188        private AllViewData InitAllViewData(string str, string er, Info inf, List<MagazineItem> list) 
     189        { 
     190            var viewData = new AllViewData 
     191            { 
     192                naglowek = str, 
     193                error = er, 
     194                info = inf, 
     195                magazine = list 
     196            }; 
     197            return viewData; 
     198        }   
    125199    } 
    126200}