Beispiel #1
0
        public ActionResult Update(Models.Administrator editAdm)
        {
            if (Session["accname"] == null)
            {
                Session["accname"] = null;
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                ViewBag.pdcListEdit = new SelectList(dbLog.Positions, "ID", "Name");

                try
                {
                    dbLog.Entry(editAdm).State = System.Data.Entity.EntityState.Modified;

                    dbLog.SaveChanges();
                    SetAlert("Cập nhật thông tin người dùng thành công!", "success");
                    return(RedirectToAction("Index", "Account"));
                }
                catch (Exception)
                {
                    ViewBag.EditProError = "Không thể cập nhật sản phẩm.";
                }
                return(View());
            }
        }
 public ActionResult Edit(Models.ProductType editType)
 {
     if (Session["accname"] == null)
     {
         Session["accname"] = null;
         return(RedirectToAction("Login", "Account"));
     }
     else
     {
         ViewBag.cateListEdit = new SelectList(dbType.Categories, "cateID", "cateName");
         try
         {
             if (ModelState.IsValid)
             {
                 dbType.Entry(editType).State = System.Data.Entity.EntityState.Modified;
                 dbType.SaveChanges();
                 ViewBag.EditTypeError = "Cập nhật loại sản phẩm thành công.";
             }
         }
         catch (Exception)
         {
             ViewBag.EditTypeError = "Không thể cập nhật loại sản phẩm.";
         }
         return(View());
     }
 }
 public ActionResult Edit(Models.Theme editCate)
 {
     if (Session["accname"] == null)
     {
         Session["accname"] = null;
         return(RedirectToAction("Login", "Account"));
     }
     else
     {
         try
         {
             EX  ex = new EX();
             var a  = ex.prtname(editCate.TenChuDe);
             int b  = a.Count();
             if (b == 0)
             {
                 dbCate.Entry(editCate).State = System.Data.Entity.EntityState.Modified;
                 dbCate.SaveChanges();
                 SetAlert("Cập nhật chủ đề thành công!", "success");
                 return(RedirectToAction("Index", "Theme"));
             }
             else
             {
                 ViewBag.CreateCategory = "Tên danh mục đã tồn tại.";
             }
         }
         catch (Exception)
         {
             ViewBag.EditCategory = "Không thể cập nhật danh mục.";
         }
         return(View());
     }
 }
Beispiel #4
0
        public ActionResult Edit(Models.News editPro)
        {
            if (Session["accname"] == null)
            {
                Session["accname"] = null;
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                ViewBag.pdcListEdit = new SelectList(news.Themes, "ID", "TenChuDe");



                try
                {
                    news.Entry(editPro).State = System.Data.Entity.EntityState.Modified;
                    news.SaveChanges();
                    SetAlert("Cập nhật tin tuc thành công!", "success");
                    return(RedirectToAction("Index", "News"));
                }
                catch (Exception)
                {
                    ViewBag.EditProError = "Không thể cập nhật tin tức.";
                }
                return(View());
            }
        }
Beispiel #5
0
 public ActionResult Edit(Models.Category editCate, HttpPostedFileBase file, string name)
 {
     if (Session["accname"] == null)
     {
         Session["accname"] = null;
         return(RedirectToAction("Login", "Account"));
     }
     else
     {
         if (file != null)
         {
             if (file.ContentLength > 0)
             {
                 try
                 {
                     string nameFile = Path.GetFileName(file.FileName);
                     file.SaveAs(Path.Combine(Server.MapPath("/Image"), nameFile));
                     editCate.catePhoto = "/Image/" + nameFile;
                 }
                 catch (Exception)
                 {
                     ViewBag.EditCategory = "Không thể chọn ảnh.";
                 }
             }
         }
         try
         {
             if (ModelState.IsValid)
             {
                 if (dbCate.Categories.SingleOrDefault(cr => cr.cateName.Equals(name)) == null)
                 {
                     editCate.cateName            = name;
                     dbCate.Entry(editCate).State = System.Data.Entity.EntityState.Modified;
                     dbCate.SaveChanges();
                     SetAlert("Cập nhật danh mục thành công!", "success");
                     return(RedirectToAction("Index", "Category"));
                 }
                 else
                 {
                     ViewBag.EditCategory = "Tên danh mục đã tồn tại.";
                 }
             }
         }
         catch (Exception)
         {
             ViewBag.EditCategory = "Không thể cập nhật danh mục.";
         }
         return(View());
     }
 }
        public ActionResult Edit(Models.Product editPro, HttpPostedFileBase file)
        {
            //if (Session["accname"] == null)
            //{
            //    Session["accname"] = null;
            //    return RedirectToAction("Login", "Account");
            //}
            //else
            //{
            ViewBag.pdcListEdit  = new SelectList(dbPro.Producers, "pdcID", "pdcName", "proPhoto");
            ViewBag.typeListEdit = new SelectList(dbPro.ProductTypes, "typeID", "typeName");

            if (file != null)
            {
                if (file.ContentLength > 0)
                {
                    try
                    {
                        string nameFile  = Path.GetFileNameWithoutExtension(file.FileName);
                        string extension = Path.GetExtension(file.FileName);
                        nameFile = nameFile + extension;
                        file.SaveAs(Path.Combine(Server.MapPath("/Image"), nameFile));
                        editPro.proPhoto = "/Image/" + nameFile;
                    }
                    catch (Exception)
                    {
                        ViewBag.EditProError = "Không thể chọn ảnh.";
                    }
                }
            }
            editPro.proUpdateDate = DateTime.Now.ToString();
            try
            {
                dbPro.Entry(editPro).State = System.Data.Entity.EntityState.Modified;
                dbPro.SaveChanges();
                //ViewBag.EditProError = "Cập nhật sản phẩm thành công.";
                return(RedirectToAction("Index", new { erro = "Cập nhật sản phẩm thành công." }));
            }
            catch (Exception)
            {
                ViewBag.EditProError = "Không thể cập nhật sản phẩm.";
            }
            return(View());
            //}
        }
 public ActionResult Edit(Models.Producer editPdc, HttpPostedFileBase file)
 {
     if (Session["accname"] == null)
     {
         Session["accname"] = null;
         return(RedirectToAction("Login", "Account"));
     }
     else
     {
         if (file != null)
         {
             if (file.ContentLength > 0)
             {
                 try
                 {
                     string nameFile = Path.GetFileName(file.FileName);
                     file.SaveAs(Path.Combine(Server.MapPath("/Image"), nameFile));
                     editPdc.pdcPhoto = "/Image/" + nameFile;
                 }
                 catch (Exception)
                 {
                     ViewBag.EditPdcError = "Không thể chọn ảnh.";
                 }
             }
         }
         try
         {
             if (ModelState.IsValid)
             {
                 dbPdc.Entry(editPdc).State = System.Data.Entity.EntityState.Modified;
                 dbPdc.SaveChanges();
                 SetAlert("Cập nhật nhà sản xuất thành công!", "success");
                 return(RedirectToAction("Index", "Producer"));
             }
         }
         catch (Exception)
         {
             ViewBag.EditPdcError = "Không thể cập nhật hãng sản xuất.";
         }
         return(View());
     }
 }
 public ActionResult Edit(Models.ProductType editType, string prtname)
 {
     if (Session["accname"] == null)
     {
         Session["accname"] = null;
         return(RedirectToAction("Login", "Account"));
     }
     else
     {
         EX  ex = new EX();
         var a  = ex.prtname(prtname);
         int b  = a.Count();
         ViewBag.cateListEdit = new SelectList(dbType.Categories, "cateID", "cateName");
         try
         {
             if (ModelState.IsValid)
             {
                 if (b != 0)
                 {
                     ViewBag.EditTypeError = "Trùng tên loại sản phẩm.";
                 }
                 else
                 {
                     editType.typeName            = prtname;
                     dbType.Entry(editType).State = System.Data.Entity.EntityState.Modified;
                     dbType.SaveChanges();
                     SetAlert("Cập nhật loại sản phẩm thành công!", "success");
                     return(RedirectToAction("Index", "ProductType"));
                 }
             }
         }
         catch (Exception)
         {
             ViewBag.EditTypeError = "Không thể cập nhật loại sản phẩm.";
         }
         return(View());
     }
 }