public ActionResult ListOfWastes() { var wastesDb = db.Wastes.ToArray(); List <WasteVM> wastesList = new List <WasteVM>(); //Fills a list with all the db wastes for (int i = 0; i < wastesDb.Length; i++) { var storageName = db.Storages.Find(wastesDb[i].PrimaryStorageId).Name; var wasteType = db.WasteTypes.Find(wastesDb[i].TypeId).Name; var wasteStatus = db.WasteStatuses.Find(wastesDb[i].WasteStatusId).Name; var waste = new WasteVM() { Id = wastesDb[i].Id, Quantity = wastesDb[i].Quantity, StorageName = storageName, Type = wasteType, Number = wastesDb[i].Number, Status = wasteStatus }; wastesList.Add(waste); } return(View(wastesList)); }
private decimal GetStorageQuantity(int storageId) { var wastesDb = db.Wastes.Where(x => x.StorageId == storageId).ToArray(); var wasteTypesDb = db.WasteTypes.ToArray(); string type; List <WasteVM> wastesList = new List <WasteVM>(); for (int i = 0; i < wastesDb.Count(); i++) { type = wasteTypesDb.FirstOrDefault(x => x.Id == wastesDb[i].TypeId).Name; var wasteVM = new WasteVM() { Id = wastesDb[i].Id, Number = wastesDb[i].Number, Quantity = wastesDb[i].Quantity, Status = wastesDb[i].WasteStatus.Name, Type = type }; wastesList.Add(wasteVM); } decimal quantity = 0; if (null != wastesList) { for (int i = 0; i < wastesList.Count(); i++) { quantity += (decimal)wastesList[i].Quantity; } } return(quantity); }
public ActionResult CreateWaste(WasteVM wasteVM) { //Db Model Waste wasteDb = new Waste(); //Fills the dbModel with the passed data wasteDb.Number = wasteVM.Number; wasteDb.Quantity = wasteVM.Quantity; wasteDb.TypeId = int.Parse(wasteVM.TypeId); wasteDb.PrimaryStorageId = int.Parse(wasteVM.PrimaryStorageId); wasteDb.StorageId = int.Parse(wasteVM.PrimaryStorageId); //WasteStatusId = 1 is the start point of the waste wasteDb.WasteStatusId = 1; if (ModelState.IsValid) { db.Wastes.Add(wasteDb); db.SaveChanges(); ViewBag.SuccessMessage = "Успешен запис!"; return(View("~/Views/Shared/SuccessPage.cshtml")); } wasteVM.Types = GetWasteTypesLI(); wasteVM.Storages = GetStoragesLI(); return(View(wasteVM)); }
public ActionResult CreateWaste() { // StorageVM for the Edit form var wasteVM = new WasteVM() { Types = GetWasteTypesLI(), Storages = GetStoragesLI() }; return(View(wasteVM)); }
public ActionResult EditWaste(int wasteId) { //Gets the selected waste var wasteDb = db.Wastes.Find(wasteId); //WasteVM for the Edit form var wasteVM = new WasteVM() { Id = wasteDb.Id, Number = wasteDb.Number, Quantity = wasteDb.Quantity, Storages = GetStoragesLI(), Types = GetWasteTypesLI() }; return(View(wasteVM)); }
private List <WasteVM> GetHistoryWastes(History historyDb) { List <WasteVM> wastesList = new List <WasteVM>(); var wastes = historyDb.Wastes.ToArray(); for (int i = 0; i < wastes.Count(); i++) { var waste = new WasteVM() { Id = wastes[i].Id, Number = wastes[i].Number, Quantity = wastes[i].Quantity, Type = wastes[i].WasteType.Name, Status = wastes[i].WasteStatus.Name }; wastesList.Add(waste); } return(wastesList); }
public ActionResult Edit(WasteVM vm) { if (!ModelState.IsValid) { return(PartialView(vm)); } else { vm.DoEdit(); if (!ModelState.IsValid) { vm.DoReInit(); return(PartialView(vm)); } else { return(FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID)); } } }
public ActionResult Create(WasteVM vm) { if (!ModelState.IsValid) { return(PartialView(vm)); } else { vm.DoAdd(); if (!ModelState.IsValid) { vm.DoReInit(); return(PartialView(vm)); } else { return(FFResult().CloseDialog().RefreshGrid()); } } }
public ActionResult WastesPartial(int storageId) { var wastesDb = db.Wastes.Where(x => x.StorageId == storageId).ToArray(); var wasteTypesDb = db.WasteTypes.ToArray(); string type; List <WasteVM> wastesList = new List <WasteVM>(); for (int i = 0; i < wastesDb.Count(); i++) { type = wasteTypesDb.FirstOrDefault(x => x.Id == wastesDb[i].TypeId).Name; var wasteVM = new WasteVM() { Id = wastesDb[i].Id, Number = wastesDb[i].Number, Quantity = wastesDb[i].Quantity, Type = type }; wastesList.Add(wasteVM); } ViewData.TemplateInfo.HtmlFieldPrefix = string.Format("Wastes"); return(PartialView("~/Views/Shared/EditorTemplates/_WasteVM.cshtml", wastesList)); }
private List <WasteVM> GetWastesByStorage(int storageId) { //Wastes var wastesDb = db.Wastes.Where(x => x.PrimaryStorageId == storageId).ToArray(); var wasteTypesDb = db.WasteTypes.ToArray(); string type; List <WasteVM> wastesList = new List <WasteVM>(); for (int i = 0; i < wastesDb.Count(); i++) { type = wasteTypesDb.FirstOrDefault(x => x.Id == wastesDb[i].TypeId).Name; var wasteVM = new WasteVM() { Id = wastesDb[i].Id, Number = wastesDb[i].Number, Quantity = wastesDb[i].Quantity, Status = wastesDb[i].WasteStatus.Name, Type = type }; wastesList.Add(wasteVM); } return(wastesList); }
public ActionResult EditWaste(WasteVM waste) { //Gets the edited waste var wasteDb = db.Wastes.Find(waste.Id); //Fills the db model wasteDb.Number = waste.Number; wasteDb.Quantity = waste.Quantity; wasteDb.TypeId = int.Parse(waste.TypeId); wasteDb.PrimaryStorageId = int.Parse(waste.PrimaryStorageId); wasteDb.WasteStatusId = 3; if (ModelState.IsValid) { db.Entry(wasteDb).State = EntityState.Modified; db.SaveChanges(); ViewBag.SuccessMessage = "Успешен запис!"; return(View("~/Views/Shared/SuccessPage.cshtml")); } waste.Types = GetWasteTypesLI(); waste.Storages = GetStoragesLI(); return(View(waste)); }
public void DoComfire() { //APIHelper.CallAPI() ////DC.RunSP("UpdateStock", Entity.ID); Entity.isComfire = true; DoEdit(); var oldWaste = DC.Set <Waste>().AsNoTracking().Where(x => x.CompanyId == new Guid(LoginUserInfo.Attributes["CompanyId"].ToString()) && x.LocationId == Entity.LocationId).SingleOrDefault(); var vml = new WasteVM(); vml.CopyContext(this); if (oldWaste == null) { vml.Entity.CompanyId = Entity.CompanyId; vml.Entity.LocationId = Entity.LocationId; vml.Entity.m10 = Entity.m10 - Entity.m10r; vml.Entity.m18 = Entity.m18 - Entity.m18r; vml.Entity.m20 = Entity.m20 - Entity.m20r; vml.Entity.m25 = Entity.m25 - Entity.m25r; vml.Entity.m28 = Entity.m28 - Entity.m28r; vml.Entity.m30 = Entity.m30 - Entity.m30r; vml.Entity.m35 = Entity.m35 - Entity.m35r; vml.Entity.m40 = Entity.m40 - Entity.m40r; vml.Entity.m50 = Entity.m50 - Entity.m50r; vml.Entity.g10 = Entity.g10 - Entity.g10r; vml.Entity.g20 = Entity.g20 - Entity.g20r; vml.Entity.g25 = Entity.g25 - Entity.g25r; vml.Entity.g30 = Entity.g30 - Entity.g30r; vml.Entity.g35 = Entity.g35 - Entity.g35r; vml.Entity.g40 = Entity.g40 - Entity.g40r; vml.Entity.g45 = Entity.g45 - Entity.g45r; vml.Entity.g50 = Entity.g50 - Entity.g50r; vml.Entity.g60 = Entity.g60 - Entity.g60r; vml.Entity.g70 = Entity.g70 - Entity.g70r; vml.Entity.g80 = Entity.g80 - Entity.g80r; vml.DoAdd(); } else { vml.Entity.ID = oldWaste.ID; vml.Entity.CompanyId = oldWaste.CompanyId; vml.Entity.LocationId = oldWaste.LocationId; vml.Entity.CreateBy = oldWaste.CreateBy; vml.Entity.CreateTime = oldWaste.CreateTime; vml.Entity.m10 = oldWaste.m10 + Entity.m10 - Entity.m10r; vml.Entity.m18 = oldWaste.m18 + Entity.m18 - Entity.m18r; vml.Entity.m20 = oldWaste.m20 + Entity.m20 - Entity.m20r; vml.Entity.m25 = oldWaste.m25 + Entity.m25 - Entity.m25r; vml.Entity.m28 = oldWaste.m28 + Entity.m28 - Entity.m28r; vml.Entity.m30 = oldWaste.m30 + Entity.m30 - Entity.m30r; vml.Entity.m35 = oldWaste.m35 + Entity.m35 - Entity.m35r; vml.Entity.m40 = oldWaste.m40 + Entity.m40 - Entity.m40r; vml.Entity.m50 = oldWaste.m50 + Entity.m50 - Entity.m50r; vml.Entity.g10 = oldWaste.g10 + Entity.g10 - Entity.g10r; vml.Entity.g20 = oldWaste.g20 + Entity.g20 - Entity.g20r; vml.Entity.g25 = oldWaste.g25 + Entity.g25 - Entity.g25r; vml.Entity.g30 = oldWaste.g30 + Entity.g30 - Entity.g30r; vml.Entity.g35 = oldWaste.g35 + Entity.g35 - Entity.g35r; vml.Entity.g40 = oldWaste.g40 + Entity.g40 - Entity.g40r; vml.Entity.g45 = oldWaste.g45 + Entity.g45 - Entity.g45r; vml.Entity.g50 = oldWaste.g50 + Entity.g50 - Entity.g50r; vml.Entity.g60 = oldWaste.g60 + Entity.g60 - Entity.g60r; vml.Entity.g70 = oldWaste.g70 + Entity.g70 - Entity.g70r; vml.Entity.g80 = oldWaste.g80 + Entity.g80 - Entity.g80r; vml.DoEdit(true); } }