public ActionResult UpdateDelete(ProjectGoldPriceTierViewModel PGTViewModel, string command) { string PageAction = ""; bool result = false; user = (UserSession)Session["User"]; if (command == "Save") { ProjectGoldPriceTierManager PGTManager = new ProjectGoldPriceTierManager(); result = PGTManager.UpdateProjectGoldPriceTier(PGTViewModel); PageAction = "UPDATE"; } else if (command == "Delete") { ProjectGoldPriceTierManager PGTManager = new ProjectGoldPriceTierManager(); result = PGTManager.DeleteProjectGoldPriceTier(PGTViewModel); PageAction = "DELETE"; } if (result) { TempData["SuccessMessage"] = PageAction + " successful"; new AuditLogManager().Audit(user.Username, DateTime.Now, "ProjectGold Price Tier", PageAction, PGTViewModel.Id, PGTViewModel.Price_Tier); } else { TempData["ErrorMessage"] = PageAction + " failed"; } return(RedirectToAction("Index")); }
// GET: ProjectGoldPriceTier 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_GOL", "HOME", "LOG"); // Get all data stored in DB table ProjectGoldPriceTierManager PGTManager = new ProjectGoldPriceTierManager(); ProjectGoldPriceTierViewModel PGTViewModel = new ProjectGoldPriceTierViewModel(); PGTViewModel.PrjPTList = PGTManager.GetPGT(); if (PGTViewModel.PrjPTList == null || PGTViewModel.PrjPTList.Count() == 0) { PGTViewModel.PrjPTList = new List <ProjectGoldPriceTierViewModel>(); } // return View with ViewModel return(View(PGTViewModel)); }
public List <ProjectGoldPriceTierViewModel> GetPGT() { using (CFMMCDEntities db = new CFMMCDEntities()) { List <ProjectGoldPriceTierViewModel> PGTList = new List <ProjectGoldPriceTierViewModel>(); foreach (Project_Gold_Price_Tier pgt in db.Project_Gold_Price_Tier) { ProjectGoldPriceTierViewModel PGTViewModel = new ProjectGoldPriceTierViewModel(); PGTViewModel.Id = (pgt.Id).ToString(); PGTViewModel.Price_Tier = pgt.Price_Tier; // Add to List PGTList.Add(PGTViewModel); } return(PGTList); } }
public bool UpdateProjectGoldPriceTier(ProjectGoldPriceTierViewModel PGTViewModel) { using (CFMMCDEntities db = new CFMMCDEntities()) { Project_Gold_Price_Tier pgtRow = new Project_Gold_Price_Tier(); pgtRow.Id = int.Parse(PGTViewModel.Id); pgtRow.Price_Tier = PGTViewModel.Price_Tier; try { if (db.Project_Gold_Price_Tier.Where(o => o.Id.ToString().Equals(PGTViewModel.Id)).Any()) { var rowToRemove = db.Project_Gold_Price_Tier.Single(o => o.Id.ToString().Equals(PGTViewModel.Id)); db.Project_Gold_Price_Tier.Remove(rowToRemove); db.Project_Gold_Price_Tier.Add(pgtRow); } else { db.Project_Gold_Price_Tier.Add(pgtRow); } 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); } } }