public IActionResult Filter(SaleFilterVM saleFilterVM) { if (saleFilterVM.SaleFiltrationModel.periodStart != null) { var buf = saleFilterVM.SaleFiltrationModel.periodStart.Split('.'); saleFilterVM.SaleFiltrationModel.startDate = new DateTime( Convert.ToInt32(buf[2]), Convert.ToInt32(buf[1]), Convert.ToInt32(buf[0])); } if (saleFilterVM.SaleFiltrationModel.periodEnd != null) { var buf = saleFilterVM.SaleFiltrationModel.periodEnd.Split('.'); saleFilterVM.SaleFiltrationModel.endDate = new DateTime( Convert.ToInt32(buf[2]), Convert.ToInt32(buf[1]), Convert.ToInt32(buf[0])); } var user = _userService.All().First(u => u.Id == saleFilterVM.UserId); ViewBag.User = user; if (user == null) { RedirectToAction("Index", "Home"); } var getAllSales = _saleService.Filtration(saleFilterVM.SaleFiltrationModel); if (user.Role != Role.Administrator) { getAllSales = getAllSales.Where(x => x.ShopId == user.ShopId); } var response = getAllSales .OrderByDescending(s => s.Id) .Select(s => new SaleVM() { Id = s.Id, Date = s.Date.ToString("dd.MM.yyyy"), Sum = s.Sum, ShopTitle = s.Shop.Title, PaymentType = _db.InfoMonies.Count(x => x.SaleId == s.Id) > 1 ? PaymentType.Mixed : _db.InfoMonies.FirstOrDefault(x => x.SaleId == s.Id) != null ? _db.InfoMonies.FirstOrDefault(x => x.SaleId == s.Id).PaymentType : PaymentType.Cash, //Пиздец HasAdditionalProduct = s.SalesProducts.FirstOrDefault(sp => sp.Additional) != null ? true : false, BuyerTitle = _db.Partners.FirstOrDefault(x => x.Id == s.PartnerId) != null ? _db.Partners.FirstOrDefault(x => s.PartnerId == x.Id).Title : "Обычный покупатель", ProductTitle = _db.SalesProducts .FirstOrDefault(z => z.SaleId == s.Id).Product.Title, PrimeCost = s.PrimeCost, MarginPercent = Convert.ToInt32(Math.Round((s.Margin == 0 || s.Sum == 0) ? 0 : s.Margin / (s.Sum / 100))) }).ToList(); var marginPercent = saleFilterVM.SaleFiltrationModel.marginPercent; if (marginPercent != "") { if (marginPercent == "17") { response = response.Where(x => x.MarginPercent <= 17).ToList(); } if (marginPercent == "28") { response = response.Where(x => x.MarginPercent >= 28).ToList(); } if (marginPercent == "1728") { response = response.Where(x => x.MarginPercent > 17 && x.MarginPercent < 28).ToList(); } } return(PartialView(response)); }