public ActionResult Create(int id) { using (var db = new ProjectWebEntities()) { if (id != 0) { return(View(db.Tbl_ProductType.Find(id))); } var view = new Tbl_ProductType(); return(View(view)); } }
public void disableProductType(Tbl_ProductType input) { using (var db = new ProjectWebEntities()) { try { var model = db.Tbl_ProductType.Find(input.Id); model.IsDisable = input.IsDisable; db.Entry(model).State = EntityState.Modified; db.SaveChanges(); db.pr_LogSystem_save("Sửa trạng thái sử dụng(" + model.Name + ")", "Sửa", "ProductType", User.Identity.Name); //Xóa cache CacheHelper.ClearAllOutputCache(); } catch (Exception ex) { logger.Error("An Error Happened! ", ex); } } }
public ActionResult Create(Tbl_ProductType model) { using (var db = new ProjectWebEntities()) { try { if (model != null) { if (Request.Form["ParentId"] != null && Request.Form["ParentId"] != "") { string[] parList = Request.Form["ParentId"].Split(','); for (int i = parList.Count() - 1; i >= 0; i--) { if (parList[i] != "") { if (int.Parse(parList[i]) > 0) { model.ParentId = int.Parse(parList[i]); break; } } } } if (model.ParentId == 0) { model.ParentId = null; } model.Url = Util.GenerateUrl(model.Name); model.Icon = Request.Form["Icon"]; model.ImagePath = Request.Form["fileName"]; // create new if (model.Id == 0) { db.Tbl_ProductType.Add(model); db.SaveChanges(); db.pr_LogSystem_save("Thêm mới dữ liệu(" + model.Name + ")", "Cập nhật", "ProductType", User.Identity.Name); } else // update current { var menu = db.Tbl_MenuMultiLevel.FirstOrDefault(p => p.PageChildId == model.Id && p.PageId == 9); if (menu != null) { menu.Url = db.Tbl_MenuLink.Find(GlobalVariables.MenuDanhmuc).Url + model.Url + "-" + model.Id; db.Entry(menu).State = EntityState.Modified; } db.Entry(model).State = EntityState.Modified; db.SaveChanges(); db.pr_LogSystem_save("Cập nhật dữ liệu(" + model.Name + ")", "Cập nhật", "ProductType", User.Identity.Name); } //Xóa cache CacheHelper.ClearAllOutputCache(); } } catch (Exception ex) { logger.Error("An Error Happened! ", ex); } return(RedirectToAction("Index", "ProductType")); } }