public ActionResult Edit(MobileViewModel Mobile, double OldPrice, int OldQuantity, string OldImage) { ViewBag.ListCategory = HttpContext.Cache[Constants.LIST_CATEGORY]; var CategoryDao = new CategoryDAO(); int CategoryId = CategoryDao.GetCategoryId(Mobile.CategoryName); if (ModelState.IsValid) { if (string.IsNullOrEmpty(Mobile.Image)) { Mobile.Image = OldImage; } var dao = new MobileDAO(); dao.EditMobile(new Mobile { MobileId = Mobile.MobileId, Name = Mobile.Name, Image = Mobile.Image, Price = Mobile.Price, Quantity = Mobile.Quantity, Status = Mobile.Status, CategoryId = CategoryId }); var UpdateDao = new UpdateTableDAO(); bool check = UpdateDao.InsertUpdateTable(new UpdateTable { MobileId = Mobile.MobileId, OldPrice = OldPrice, OldQuantity = OldQuantity, NewPrice = Mobile.Price, NewQuantity = Mobile.Quantity, StatusUpdate = "Edit", Email = ((AccountLogin)Session[Constants.USER_SESSION]).Email, TimeUpdate = DateTime.Now, }); TempData["ChangeStatus"] = "Update Successful !"; } else { ModelState.AddModelError("", "Update is not Successful !"); return(View("Edit")); } return(RedirectToAction("Index")); }
public ActionResult Delete(int id) { var dao = new MobileDAO(); bool check = dao.RemoveMobile(id); var UpdateDao = new UpdateTableDAO(); UpdateDao.InsertUpdateTable(new UpdateTable { MobileId = id, StatusUpdate = "Delete", Email = ((AccountLogin)Session[Constants.USER_SESSION]).Email, TimeUpdate = DateTime.Now, }); if (check) { TempData["ChangeStatus"] = "Delete Successful !"; } else { ModelState.AddModelError("", "Delete Fail !"); } return(RedirectToAction("Index")); }