public ActionResult Edit([Bind(Include = "DeviceId,DeviceName,DescriptionDevice,Components,Shop,MadeInCountry,Quantity,Price,file,Category")] TblDevice tblDevice, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                tblDevice.Active = true;

                bool fileUploaded = false;

                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    var path     = Path.Combine(Server.MapPath("~/Content/DeviceImages/"), fileName);
                    file.SaveAs(path);

                    fileUploaded = true;
                }

                if (fileUploaded)
                {
                    tblDevice.Picture         = file.FileName;
                    db.Entry(tblDevice).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    if (tblDevice.Picture != null)
                    {
                        db.Entry(tblDevice).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        tblDevice.Picture         = Request["altfile"];
                        db.Entry(tblDevice).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.Category = new SelectList(db.TblCategories, "CategoryId", "CategoryName", tblDevice.Category);
            ViewBag.Shop     = new SelectList(db.TblShops, "ShopId", "ShopName", tblDevice.Shop);
            return(View(tblDevice));
        }
Пример #2
0
 public ActionResult Edit([Bind(Include = "CategoryId,CategoryName,Description,Subcategory")] TblCategory tblCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tblCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tblCategory));
 }
Пример #3
0
 public ActionResult Edit([Bind(Include = "ShopId,ShopName,Address,NoOfEmployees,TaxIdentificationNo,DateOfFounding")] TblShop tblShop)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tblShop).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tblShop));
 }