public ActionResult ShowAllSales(int?manager, string product, string date) { using (IPL db = new PL()) { IEnumerable <SaleViewModel> sales = db.GetSales(); IList <ManagerViewModel> managers = db.GetManagers().ToList(); managers.Insert(0, new ManagerViewModel { ManagerID = 0, LastName = "Все" }); IList <string> products = sales.Select(x => x.Product).Distinct().ToList(); products.Insert(0, "Любой"); IList <DateTime> dates = sales.Select(x => x.Date).Distinct().ToList(); IList <string> datesForFilter = new List <string>(); foreach (var item in dates) { datesForFilter.Add(String.Format("{0:d}", item)); } datesForFilter.Insert(0, "Даты нет"); datesForFilter = datesForFilter.Distinct().ToList(); FilterModel filter = new FilterModel { Sales = sales, Managers = new SelectList(managers, "ManagerId", "LastName"), Products = new SelectList(products), Dates = new SelectList(datesForFilter) }; return(View(filter)); } }
public ActionResult FilterSales(int?manager, string product, string date) { using (IPL db = new PL()) { IEnumerable <SaleViewModel> sales = db.GetSales(); if (manager != 0 && manager != null) { sales = sales.Where(x => x.ManagerId == manager); } if (!String.IsNullOrEmpty(product) && !product.Equals("Любой")) { sales = sales.Where(x => x.Product == product); } if (date != null && !date.Equals("Даты нет")) { DateTime time; DateTime.TryParse(date, out time); sales = sales.Where(x => x.Date.Day == time.Day && x.Date.Month == time.Month && x.Date.Year == time.Year); } FilterModel filter = new FilterModel { Sales = sales }; return(PartialView(filter)); } }
public JsonResult DrawChart() { ICollection <Models.ManagerChartModel> data = new List <Models.ManagerChartModel>(); using (IPL db = new PL()) { var sales = db.GetSales(); var managers = db.GetManagers(); foreach (var item in managers) { data.Add(new ManagerChartModel { ManagerName = item.LastName, NumberOfSales = sales.Where(x => x.ManagerId == item.ManagerID).Count() }); } } return(Json(new { Data = data }, JsonRequestBehavior.AllowGet)); }