public ActionResult UpdateDelete(MDSPriceTierViewModel MDSViewModel, string command) { string PageAction = ""; bool result = false; user = (UserSession)Session["User"]; if (command == "Save") { MDSPriceTierManager MDSManager = new MDSPriceTierManager(); result = MDSManager.UpdateMDSPriceTier(MDSViewModel); PageAction = "UPDATE"; } else if (command == "Delete") { MDSPriceTierManager MDSManager = new MDSPriceTierManager(); result = MDSManager.DeleteMDSPriceTier(MDSViewModel); PageAction = "DELETE"; } if (result) { TempData["SuccessMessage"] = PageAction + " successful"; new AuditLogManager().Audit(user.Username, DateTime.Now, "MDS Price Tier", PageAction, MDSViewModel.Id, MDSViewModel.Price_Tier); } else { TempData["ErrorMessage"] = PageAction + " failed"; } return(RedirectToAction("Index")); }
// GET: MDSPriceTier public ActionResult Index() { // Validate log in and user access UserAccessSession UASession = (UserAccessSession)Session["UserAccess"]; // TIP -> Price Tier // Refer to UserAccessSession if (UASession == null || !UASession.TIP) { return(RedirectToAction("Login", "Account")); } user = (UserSession)Session["User"]; Session["CurrentPage"] = new CurrentPageSession("TIP_MDS", "HOME", "LOG"); // Get all data stored in DB table MDSPriceTierManager MDSManager = new MDSPriceTierManager(); MDSPriceTierViewModel MDSViewModel = new MDSPriceTierViewModel(); MDSViewModel.MDPTList = MDSManager.GetMDS(); if (MDSViewModel.MDPTList == null || MDSViewModel.MDPTList.Count() == 0) { MDSViewModel.MDPTList = new List <MDSPriceTierViewModel>(); } // return View with ViewModel return(View(MDSViewModel)); }
public List <MDSPriceTierViewModel> GetMDS() { using (CFMMCDEntities db = new CFMMCDEntities()) { List <MDSPriceTierViewModel> MDSList = new List <MDSPriceTierViewModel>(); foreach (MDS_Price_Tier mds in db.MDS_Price_Tier) { MDSPriceTierViewModel MDSViewModel = new MDSPriceTierViewModel(); MDSViewModel.Id = (mds.Id).ToString(); MDSViewModel.Price_Tier = mds.Price_Tier; // Add to List MDSList.Add(MDSViewModel); } return(MDSList); } }
public bool UpdateMDSPriceTier(MDSPriceTierViewModel MDSViewModel) { using (CFMMCDEntities db = new CFMMCDEntities()) { MDS_Price_Tier mdsRow = new MDS_Price_Tier(); mdsRow.Id = int.Parse(MDSViewModel.Id); mdsRow.Price_Tier = MDSViewModel.Price_Tier; try { if (db.MDS_Price_Tier.Where(o => o.Id.ToString().Equals(MDSViewModel.Id)).Any()) { var rowToRemove = db.MDS_Price_Tier.Single(o => o.Id.ToString().Equals(MDSViewModel.Id)); db.MDS_Price_Tier.Remove(rowToRemove); db.MDS_Price_Tier.Add(mdsRow); } else { db.MDS_Price_Tier.Add(mdsRow); } db.SaveChanges(); return(true); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Source); System.Diagnostics.Debug.WriteLine(e.Message); System.Diagnostics.Debug.WriteLine(e.StackTrace); System.Diagnostics.Debug.WriteLine(e.InnerException); Exception f = e.InnerException; while (f != null) { System.Diagnostics.Debug.WriteLine("INNER:"); System.Diagnostics.Debug.WriteLine(f.Message); System.Diagnostics.Debug.WriteLine(f.Source); f = f.InnerException; } System.Diagnostics.Debug.WriteLine(e.Data); return(false); } } }