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");
            }
        }
Пример #2
0
        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;
        }
Пример #3
0
 public void Delete(PalletGroup palletGroupToDelete)
 {
     Delete(palletGroupToDelete.ID);
 }
Пример #4
0
        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;
        }
Пример #5
0
 public PalletGroup Get(PalletGroup palletGroupToGet)
 {
     return Get(palletGroupToGet.Name);
 }
Пример #6
0
 public void Destroy(PalletGroup palletGroupToDestroy)
 {
     Destroy(palletGroupToDestroy.ID);
 }