public ActionResult Edit(Category category, HttpPostedFileBase CategoryImgUrl)
        {
            if (ModelState.IsValid)
            {
                var c = db.Categories.Find(category.ID);
                if (CategoryImgUrl != null)
                {
                    var path = Server.MapPath("/Uploads/Categories/");

                    if (c.CategoryImageURL != null)
                    {
                        System.IO.File.Delete(path + c.CategoryImageURL);
                    }

                    //string old = path + ;
                    string _new = path + CategoryImgUrl.FileName;
                    CategoryImgUrl.SaveAs(_new);
                    c.CategoryImageURL = CategoryImgUrl.FileName;
                }
                c.CategoryName    = category.CategoryName;
                db.Entry(c).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(category));
        }
Beispiel #2
0
 public bool Update(T newRecord)
 {
     try
     {
         var old = GetOne(newRecord.ID);
         _db.Entry(old).CurrentValues.SetValues(newRecord);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Beispiel #3
0
 public ActionResult Edit(Treat treat, int FlavorId)
 {
     if (FlavorId != 0)
     {
         _db.FlavorTreat.Add(new FlavorTreat()
         {
             FlavorId = FlavorId, TreatId = treat.TreatId
         });
     }
     _db.Entry(treat).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
        public ActionResult Edit(Treat treat, int FlavorId)
        {
            var existingConnection = _db.TreatFlavor.FirstOrDefault(join => join.TreatId == treat.TreatId && join.FlavorId == FlavorId);

            if (existingConnection == null && FlavorId != 0)
            {
                _db.TreatFlavor.Add(new TreatFlavor()
                {
                    FlavorId = FlavorId, TreatId = treat.TreatId
                });
            }
            _db.Entry(treat).State = EntityState.Modified;
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #5
0
        public ActionResult Edit(Product product, HttpPostedFileBase ProductImageURL)
        {
            if (ModelState.IsValid)
            {
                var p = db.Products.Find(product.ID);
                if (ProductImageURL != null)
                {
                    var path = Server.MapPath("/Uploads/Products/");

                    if (p.ProductImageUrl != null)
                    {
                        System.IO.File.Delete(path + p.ProductImageUrl);
                    }

                    //string old = path + ;
                    string _new = path + ProductImageURL.FileName;
                    ProductImageURL.SaveAs(_new);
                    p.ProductImageUrl = ProductImageURL.FileName;
                }
                p.Calori             = product.Calori;
                p.Piece              = product.Piece;
                p.ProductDescription = product.ProductDescription;
                p.ProductName        = product.ProductName;
                p.CategoryID         = product.CategoryID;
                p.ProductPrice       = product.ProductPrice;
                db.Entry(p).State    = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CatergoryId = _uw.Categories.GetAll().Select(x => new SelectListItem
            {
                Text  = x.CategoryName,
                Value = x.ID.ToString()
            });
            return(View(product));
        }
 public ActionResult Edit(Treat treat)
 {
     _db.Entry(treat).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Details", new { id = treat.TreatId }));
 }
Beispiel #7
0
 public ActionResult Edit(Flavor flavor)
 {
     _db.Entry(flavor).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }