public ActionResult AddShopSelectionList(MedFilterModel model) { List<MedShop> shopList = Db.MedShopSet.Where(w => !w.Deleted).ToList(); if(model.ShopSelectionList!=null && model.ShopSelectionList.Count>0) { List<Guid> selectedShops = model.ShopSelectionList.Where(w => w.IsSelected).Select(s => s.Id).ToList(); shopList.ForEach(f=>f.IsSelected=selectedShops.Contains(f.Id)); Db.SaveChanges(); } return RedirectToAction("Index"); }
private void GetMedFilterModelWithPrices(MedFilterModel model, bool isExcelOutput) { int maxResults = 1500; List<MedShop> activeShops = Db.MedShopSet.Where(w => w.IsSelected).ToList(); List<Guid> activeShopsIds = activeShops.Select(s => s.Id).ToList(); model.SelectedShopCount = activeShops.Count; IQueryable<MedPriceList> query = Db.MedPriceListSet.Where(w => !w.Deleted && activeShopsIds.Contains(w.MedShopId)); if(!string.IsNullOrEmpty(model.SelectedAptCode)) { query = query.Where(w => w.AptCode.ToLower().Contains(model.SelectedAptCode.ToLower())); } if(!string.IsNullOrEmpty(model.SelectedShopName)) { query = query.Where(w => w.MedShop.Name.ToLower().Contains(model.SelectedShopName.ToLower())); } if(!string.IsNullOrEmpty(model.SelectedTreeElement)) { query = query.Where(w => w.ATC.ToLower().Contains(model.SelectedTreeElement)); } if (isExcelOutput) { model.ActiveShopIdNameDictionary = activeShops.OrderBy(o => o.Name).ToDictionary(k => k.Id, k => k.Name); model.ExcelReportRows = query.GroupBy(g => g.AptCode).OrderBy(o => o.Key).ToDictionary(k => k.Key, k =>k.Select(s =>new ExcelReportRow() { AtcCode = s.ATC, MedName = s.Name, Price = s.Price, ShopId = s.MedShopId }).ToList()); model.ResultCount = model.ExcelReportRows.Count; } else { List<MedPriceList> pricelist = query.OrderBy(o => o.AptCode).ThenBy(o => o.MedShop.Name).Take(maxResults).ToList(); model.ReportRows = pricelist.Select( s => new ReportRow() { AptCode = s.AptCode, MedName = s.Name, ShopName = s.MedShop.Name, AtcCode = s.ATC, Price = s.Price.ToString(), LastUpdated = s.MedShop.LastUpdated.ToShortDateString() }).ToList(); model.ResultCount = model.ReportRows.Count; } }
private void GetKeyValueDates(MedFilterModel model) { KeyValue kvLastUpdate = db.KeyValueSet.FirstOrDefault(w => w.Code == PricelistScanner.LastUpdateDateKey); if(kvLastUpdate!=null) { DateTime dt=DateTime.Now; if (DateTime.TryParse(kvLastUpdate.Value, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) { model.LastScan = dt.ToString("dd MMMM yyyy HH:mm"); } } KeyValue kvNextUpdate = db.KeyValueSet.FirstOrDefault(w => w.Code == PricelistScanner.NextRunDateKey); if(kvNextUpdate!=null && !string.IsNullOrEmpty(kvNextUpdate.Value)) { model.NextScan = DateTime.Parse(kvNextUpdate.Value).ToString("dd MMMM yyyy HH:mm"); } }
public ActionResult SearchPrices(MedFilterModel model) { bool isExcelOutput = model.Excel!=null && model.Excel=="Koosta Excel"; GetMedFilterModelWithPrices(model, isExcelOutput); if(isExcelOutput) { ExcelWorkbook excelWorkbook = GenerateExcel(model.ExcelReportRows, model.ActiveShopIdNameDictionary); byte[] excelInBytes = ConvertStringToByteArray(excelWorkbook.GetXML()); return File(excelInBytes, "application/ms-excel", "Ravimiinfo_hinnakiri_" + DateTime.Now.ToString("yyyyMMdd")+".xls"); } return PartialView("ReportPartial", model); }
public ActionResult Index() { ViewBag.Message = "Südameapteegi ravimiinfo baas"; MedFilterModel model=new MedFilterModel(); GetMedFilterModelWithPrices(model,false); GetKeyValueDates(model); return View(model); }
public ActionResult GetShopSelectionList() { MedFilterModel model=new MedFilterModel(); List<MedShop> shopList = Db.MedShopSet.Where(w=>!w.Deleted).ToList(); model.ShopSelectionList = shopList.Select(s => new SelectionItem() {Id = s.Id, Name = s.Name, Code=s.Code, IsSelected = s.IsSelected}).OrderBy(o=>o.Name).ToList(); return PartialView("ShopSelectionList", model); }