private ActionResult ViewDetail(TblProductModel 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; } ViewData["optCategory"] = uow.Modules.ProductCategory.Gets(); return(View(ob)); } catch (Exception ex) { return(RedirectToAction("Index", MVCController, new { area = MVCArea, msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); } }
public ActionResult Delete() { try { int id = Request.Form["ModelId"].ParseInt(); TblProductModel ob = uow.Modules.ProductModel.Get(id); if (ob == null) { return(RedirectToAction("Index", MVCController, new { msg = "ไม่พบข้อมูลที่ต้องการ", msgType = AlertMsgType.Warning })); } uow.Modules.ProductModel.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 SetDetail() { int id = Request.Form["ModelId"].ParseInt(); TblProductModel ob = uow.Modules.ProductModel.Get(id); if (ob.ModelId <= 0) { ob.CategoryId = Request.Form["CategoryId"].ParseInt(); ob.Category = uow.Modules.ProductCategory.Get(ob.CategoryId); ob.CreatedBy = CurrentUID; ob.CreatedDate = CurrentDate; } ob.ModelName = Request.Form["ModelName"]; ob.ModelOrder = Request.Form["ModelOrder"].ParseInt(); ob.UpdatedBy = CurrentUID; ob.UpdatedDate = CurrentDate; try { //Validate model b4 save uow.Modules.ProductModel.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)); } }
public ActionResult Detail(int?id, string msg, AlertMsgType?msgType) { TblProductModel ob = uow.Modules.ProductModel.Get(id ?? 0); return(ViewDetail(ob, msg, msgType)); }