public ActionResult SetDetail() { int id = Request.Form["CategoryId"].ParseInt(); TblProductCategory ob = uow.Modules.ProductCategory.Get(id); if (ob.CategoryId <= 0) { ob.CreatedBy = CurrentUID; ob.CreatedDate = CurrentDate; } ob.CategoryName = Request.Form["CategoryName"]; ob.CategoryOrder = Request.Form["CategoryOrder"].ParseInt(); ob.UpdatedBy = CurrentUID; ob.UpdatedDate = CurrentDate; try { //Validate model b4 save uow.Modules.ProductCategory.Set(ob); uow.SaveChanges(); return(RedirectToAction("Index", new { area = "", controller = MVCController, msg = "บันทึกข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success })); } catch (Exception ex) { string msg = ex.GetMessage(true); return(ViewDetail(ob, msg, AlertMsgType.Danger)); } }
private ActionResult ViewDetail(TblProductCategory ob, string msg, AlertMsgType?msgType) { try { if (ob == null) { throw new Exception("ไม่พบข้อมูลที่ต้องการ, กรุณาลองใหม่อีกครั้ง"); } if (!string.IsNullOrWhiteSpace(msg)) { WidgetAlertModel alert = new WidgetAlertModel() { Message = msg }; if (msgType.HasValue) { alert.Type = msgType.Value; } ViewBag.Alert = alert; } return(View(ob)); } catch (Exception ex) { return(RedirectToAction("Index", MVCController, new { area = MVCArea, msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); } }
// GET: ProductCategories/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TblProductCategory tblProductCategory = db.TblProductCategories.Find(id); if (tblProductCategory == null) { return(HttpNotFound()); } return(View(tblProductCategory)); }
public ActionResult Edit(TblProductCategory tblProductCategory) { try { if (ModelState.IsValid) { db.Entry(tblProductCategory).State = EntityState.Modified; db.SaveChanges(); TempData["msg"] = "2"; return(RedirectToAction("Index")); } TempData["msg"] = "0"; } catch (Exception ex) { TempData["msg"] = "0"; } return(View(tblProductCategory)); }
public ActionResult Delete() { try { int id = Request.Form["CategoryId"].ParseInt(); TblProductCategory ob = uow.Modules.ProductCategory.Get(id); if (ob == null) { return(RedirectToAction("Index", MVCController, new { msg = "ไม่พบข้อมูลที่ต้องการ", msgType = AlertMsgType.Warning })); } uow.Modules.ProductCategory.Delete(ob); uow.SaveChanges(); return(RedirectToAction("Index", MVCController, new { msg = "ลบข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success })); } catch (Exception ex) { return(RedirectToAction("Index", MVCController, new { msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); } }
public ActionResult Create(TblProductCategory tblProductCategory) { try { if (ModelState.IsValid) { db.TblProductCategories.Add(tblProductCategory); db.SaveChanges(); TempData["msg"] = "1"; return(RedirectToAction("Index")); } TempData["msg"] = "0"; } catch (Exception ex) { TempData["msg"] = "0"; } return(View(tblProductCategory)); }
public ActionResult Delete() { int cusId = Request.Form["CustomerId"].ParseInt(); try { int id = Request.Form["AddressId"].ParseInt(); TblProductCategory ob = uow.Modules.ProductCategory.Get(id); if (ob == null) { return(RedirectToAction("Detail", "Customer", new { msg = "ไม่พบข้อมูลที่ต้องการ", msgType = AlertMsgType.Warning, id = cusId })); } uow.Modules.ProductCategory.Delete(ob); uow.SaveChanges(); return(RedirectToAction("Detail", "Customer", new { msg = "ลบข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success, id = cusId })); } catch (Exception ex) { return(RedirectToAction("Detail", "Customer", new { msg = ex.GetMessage(), msgType = AlertMsgType.Danger, id = cusId })); } }
public ActionResult Detail(int?id, string msg, AlertMsgType?msgType) { TblProductCategory ob = uow.Modules.ProductCategory.Get(id ?? 0); return(ViewDetail(ob, msg, msgType)); }