Exemple #1
0
 public ActionResult Create(InventoriesManagement inventory, HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         if (image != null)
         {
             inventory.Picture = new byte[image.ContentLength];
             image.InputStream.Read(inventory.Picture, 0, image.ContentLength);
         }
         dbContext.Inventories.Add(inventory);
         dbContext.SaveChanges();
         return(RedirectToAction("List"));
     }
     return(View(inventory));
 }
Exemple #2
0
        public ActionResult Update(InventoriesManagement inventory, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                var inventoryToUpdate = dbContext.Inventories.SingleOrDefault(x => x.InventoryID == inventory.InventoryID);


                if (image != null)
                {
                    inventory.Picture = new byte[image.ContentLength];
                    image.InputStream.Read(inventory.Picture, 0, image.ContentLength);
                }
                if (image == null && inventoryToUpdate != null)
                {
                    inventory.Picture = inventoryToUpdate.Picture;
                }
                dbContext.Set <InventoriesManagement>().AddOrUpdate(inventory);
                //dbContext.Entry(inventory).State = System.Data.Entity.EntityState.Modified;
                dbContext.SaveChanges();
                return(RedirectToAction("List"));
            }
            return(View(inventory));
        }
Exemple #3
0
        public ViewResult Create()
        {
            var model = new InventoriesManagement();

            return(View(model));
        }