public ActionResult Edit(int id) { TempData["SuccessMsg"] = ""; TempData["FailedMsg"] = ""; if (id > 0) { var model = db.FndFlexValue.Find(id); if (model == null) { TempData["FailedMsg"] = "Unit Not Found"; } else { var data = new VmUnitAdd { UnitHeaderId = model.FlexValueId, UnitName = model.FlexValue }; return(View(data)); } } else { TempData["FailedMsg"] = "Invalid Url"; } return(Redirect(Request.UrlReferrer.ToString())); }
public ActionResult Edit(VmUnitAdd model) { TempData["SuccessMsg"] = ""; TempData["FailedMsg"] = ""; if (ModelState.IsValid) { try { var data = db.FndFlexValue.Find(model.UnitHeaderId); if (data == null) { TempData["FailedMsg"] = "Unit Not Found"; } else { data.FlexValue = model.UnitName; db.SaveChanges(); TempData["SuccessMsg"] = "Unit Updated Successfully"; return(RedirectToAction("Index")); } } catch (Exception e) { TempData["FailedMsg"] = e.Message; } } else { TempData["FailedMsg"] = "Failed"; } return(View(model)); }
public ActionResult Add(VmUnitAdd model) { TempData["SuccessMsg"] = ""; TempData["FailedMsg"] = ""; if (ModelState.IsValid) { try { if (db.FndFlexValueSet.Where(w => w.FlexValueSetShortName == "unit").FirstOrDefault().FndFlexValue.Any(a => a.FlexValue == model.UnitName)) { TempData["FailedMsg"] = "Unit Already Exist"; } else { var newData = new FndFlexValue { FlexValueId = model.UnitHeaderId, FlexValue = model.UnitName, FlexValueSetId = db.FndFlexValueSet.FirstOrDefault(w => w.FlexValueSetShortName == "unit").FlexValueSetId }; db.FndFlexValue.Add(newData); db.SaveChanges(); TempData["SuccessMsg"] = "Unit Added Successfully"; return(RedirectToAction("Index")); } } catch (Exception e) { TempData["FailedMsg"] = e.Message; } } else { TempData["FailedMsg"] = "Failed"; } return(View(model)); }