public ActionResult UpdateDelete(SCMRecipeViewModel SCMViewModel, string command) { SCMRecipeManager SCMManager = new SCMRecipeManager(); UserSession user = (UserSession)Session["User"]; string PageAction = ""; bool result = false; if (command == "Save") { result = SCMRecipeManager.UpdateSCMRecipe(SCMViewModel, user.Username); PageAction = "Update"; } else { result = SCMRecipeManager.UpdateSCMRecipe(SCMViewModel, user.Username); return(RedirectToAction("Index", new { id = SCMViewModel.CSMDES })); } if (result) { TempData["SuccessMessage"] = PageAction + " successful"; new AuditLogManager().Audit(user.Username, DateTime.Now, "SCM Recipe", PageAction, "N/A", SCMViewModel.CSMDES); } else { TempData["ErrorMessage"] = PageAction + " failed"; } return(RedirectToAction("Index")); }
public ActionResult Index(SCMRecipeViewModel SCMViewModel, string command) { SCMViewModel = SCMRecipeManager.SearchSCMRecipe(SCMViewModel.SearchItem); if (SCMViewModel.SCMRecipeList != null) { TempData["SearchResult"] = 1; // Stores 1 if a search returned results. Session["ViewModelList"] = SCMViewModel.SCMRecipeList; } else { ModelState.AddModelError("", "No results found"); } return(View(SCMViewModel)); }
public static SCMRecipeViewModel SearchSCMRecipe(string SearchItem) { using (CFMMCDEntities db = new CFMMCDEntities()) { SCMRecipeViewModel CSMList = new SCMRecipeViewModel(); if (SearchItem == null || SearchItem.Equals("")) { return(CSMList); } CSMList.CSMDES = SearchItem; CSMList.RawItemList = SearchSCMRawItem(SearchItem); return(CSMList); } }
// GET: ValueMeal public ActionResult Index(string id) { UserAccessSession UASession = (UserAccessSession)Session["UserAccess"]; if (UASession == null || !UASession.SCM) { return(RedirectToAction("Login", "Account")); } // Set NavBar Links accordingly Session["CurrentPage"] = new CurrentPageSession("SCM", "HOME", "LOG"); // SearchItemSelected is assigned value at DisplaySearchResult SCMRecipeViewModel SCMViewModel = new SCMRecipeViewModel(); if (id != null) { SCMViewModel = SCMRecipeManager.SearchSCMRecipe(id); } return(View(SCMViewModel)); }
public static bool UpdateSCMRecipe(SCMRecipeViewModel CSMViewModel, string user) { using (CFMMCDEntities db = new CFMMCDEntities()) { if (CSMViewModel.CSMDES == null || CSMViewModel.CSMDES.Equals("")) { return(false); } // Existing foreach (var v in CSMViewModel.RawItemList) { // Delete overwritten RIMRIC entry if (!v.PreviousRIMRIC.Equals(v.RIMRIC) && db.CSM_Master_Recipe.Where(o => o.CSMDES.ToString().Equals(CSMViewModel.CSMDES)).Any()) { SCM_Master_Recipe CSMRowToDelete = db.SCM_Master_Recipe.Single(o => o.CSMID.Equals(v.CSMID)); db.SCM_Master_Recipe.Remove(CSMRowToDelete); db.SaveChanges(); } SCM_Master_Recipe CSMRow = new SCM_Master_Recipe(); CSMRow.CSMID = v.CSMID; CSMRow.CSMDES = CSMViewModel.CSMDES; CSMRow.RIMRIC = int.Parse(v.RIMRIC); if (v.CSMSFQ != null) { CSMRow.CSMSFQ = double.Parse(v.CSMSFQ); } CSMRow.CSMCWC = v.CSMCWC; try { if (db.SCM_Master_Recipe.Where(o => o.CSMID.Equals(CSMRow.CSMID)).Any()) { SCM_Master_Recipe rowToDelete = db.SCM_Master_Recipe.Single(o => o.CSMID.Equals(CSMRow.CSMID)); db.SCM_Master_Recipe.Remove(rowToDelete); db.SCM_Master_Recipe.Add(CSMRow); } else { db.SCM_Master_Recipe.Add(CSMRow); } db.SaveChanges(); } 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.Data); foreach (var eve in ((DbEntityValidationException)e).EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"", ve.PropertyName, eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName), ve.ErrorMessage); } } return(false); } } // New if (!CSMViewModel.RIMRIC[0].Equals("") && !CSMViewModel.CSMDES.Equals("")) { for (int i = 0; i < CSMViewModel.RIMRIC.Count(); i++) { string rimric = CSMViewModel.RIMRIC[i]; if (db.SCM_Master_Recipe.Where(o => (o.RIMRIC.ToString().Equals(rimric) && o.CSMDES.Equals(CSMViewModel.CSMDES))).Any()) { continue; } SCM_Master_Recipe CSMRow = new SCM_Master_Recipe(); CSMRow.CSMID = (new Random().Next(1, 999)).ToString() + CSMViewModel.RIMRIC[i]; CSMRow.CSMDES = CSMViewModel.CSMDES; CSMRow.RIMRIC = int.Parse(CSMViewModel.RIMRIC[i]); if (CSMViewModel.CSMSFQ[i] != null && !CSMViewModel.CSMSFQ[i].Equals("")) { CSMRow.CSMSFQ = double.Parse(CSMViewModel.CSMSFQ[i]); } CSMRow.CSMCWC = CSMViewModel.CSMCWC[i]; try { if (db.SCM_Master_Recipe.Where(o => o.CSMID.Equals(CSMRow.CSMID)).Any()) { SCM_Master_Recipe rowToDelete = db.SCM_Master_Recipe.Single(o => o.CSMID.Equals(CSMRow.CSMID)); db.SCM_Master_Recipe.Remove(rowToDelete); db.SCM_Master_Recipe.Add(CSMRow); } else { db.SCM_Master_Recipe.Add(CSMRow); } db.SaveChanges(); } 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); } } } return(true); } }