/// <summary> /// Handle the PPE Types on LEFT (i.e. basic details HWCs submit) /// </summary> void updateBasicPpeDetails(EditSuppliesPost s) { List <PpeTypes> existingPpeTypes = SupplierPpeTypes.SelectToList(p => (PpeTypes)p.PpeTypeId); //create new List <SupplierPpeTypeModel> ppeTypesToAdd = s.Supplies.PpeTypes.WhereToList(p => p.Selected && !existingPpeTypes.Contains(p.Type)); foreach (SupplierPpeTypeModel supplierPpeTypeViewModel in ppeTypesToAdd) { SupplierPpeType ppeTypeToAdd = SupplierPpeType.Create_FromViewModel(supplierPpeTypeViewModel, this); SupplierPpeTypes.Add(ppeTypeToAdd); } //remove deselected List <SupplierPpeTypeModel> ppeTypesToRemove = s.Supplies.PpeTypes.WhereToList(p => !p.Selected && existingPpeTypes.Contains(p.Type)); foreach (SupplierPpeTypeModel supplierPpeTypeViewModel in ppeTypesToRemove) { SupplierPpeType typeToRemove = SupplierPpeTypes.Single(p => p.PpeTypeId == (byte)supplierPpeTypeViewModel.Type); SupplierPpeTypes.Remove(typeToRemove); } //edit rest (existing) List <SupplierPpeTypeModel> ppeTypesToModify = s.Supplies.PpeTypes.WhereToList(p => p.Selected && existingPpeTypes.Contains(p.Type)); foreach (SupplierPpeTypeModel supplierPpeTypeViewModel in ppeTypesToModify) { SupplierPpeType supplierExisting = SupplierPpeTypes.SingleOrDefault(p => p.PpeTypeId == (byte)supplierPpeTypeViewModel.Type); supplierExisting?.Modify(supplierPpeTypeViewModel); } }
public void Modify(EditSuppliesPost s, string currentUserId) { Modify(s.Supplies); StatusId = (int)s.Status.Status; updateBasicPpeDetails(s); Latitude = s.Location.Latitude; Longitude = s.Location.Longitude; if (!String.IsNullOrWhiteSpace(s.Notes.NewNote)) { SupplierNote newNote = new SupplierNote { Supplier = this, Note = new Note { Timestamp = DateTimeOffset.Now, UserId = currentUserId, Text = s.Notes.NewNote, } }; SupplierNotes.Add(newNote); } }
public IActionResult EditSupplies([FromServices] DataContext dataContext, EditSuppliesPost data) { SimpleNotifier noty = notifier(); if (!ModelState.IsValid) { noty.AddMessage(MsgTypes.Warning, "Problems saving, please try again"); return(View("EditSupplies", EditSuppliesViewModel.FromPostData(data))); } else { Supplier existingSupplies = dataContext.Suppliers.Include(p => p.SupplierPpeTypes).Single(n => n.Id == data.Supplies.Id); existingSupplies.Modify(data, currentUserId); dataContext.SaveChanges(currentUserName); noty.AddMessage(MsgTypes.Success, "Successfully updated Supplier"); return(Redirect("/suppliers")); } }