public ActionResult Create(PalletGroupCreateViewModel model) { if (!ModelState.IsValid) { return View(model); } using (var db = new ApplicationDbContext()) { List<PalletDescriptor> palletDescriptorsToAdd = new List<PalletDescriptor>(); foreach (var id in model.PalletDescriptorID) { palletDescriptorsToAdd.Add(db.PalletDescriptors.Single(p => p.ID == id)); } PalletGroup palletGroupToCreate = new PalletGroup { Name = model.Name, IsDeleted = false, DateAdded = DateTime.Now, Items = new List<Item>(), PalletDescriptors = palletDescriptorsToAdd }; db.PalletGroups.Add(palletGroupToCreate); db.SaveChanges(); return RedirectToAction("Index"); } }
public int Create(PalletGroup palletGroupToCreate) { if (palletGroupToCreate == null) { throw new Exception("The pallet group sent in for creation is null"); } base.UpdateDateAdded(palletGroupToCreate); base.UpdateIsDeletedToFalse(palletGroupToCreate); db.PalletGroups.Add(palletGroupToCreate); db.SaveChanges(); int idOfPalletGroup = palletGroupToCreate.ID; return idOfPalletGroup; }
public void Delete(PalletGroup palletGroupToDelete) { Delete(palletGroupToDelete.ID); }
public int Update(PalletGroup updatedPalletGroup) { PalletGroup palletGroupToUpdate = db.PalletGroups.SingleOrDefault(c => c.ID == updatedPalletGroup.ID && c.IsDeleted == false); if (palletGroupToUpdate == null) { throw new Exception("There is no Pallet Group with the ID " + updatedPalletGroup.ID); } base.UpdateDateUpdated(updatedPalletGroup); db.PalletGroups.AddOrUpdate(c => c.ID, updatedPalletGroup); db.SaveChanges(); int idOfPalletGroup = updatedPalletGroup.ID; return idOfPalletGroup; }
public PalletGroup Get(PalletGroup palletGroupToGet) { return Get(palletGroupToGet.Name); }
public void Destroy(PalletGroup palletGroupToDestroy) { Destroy(palletGroupToDestroy.ID); }