public ActionResult Create(EnergyMaster model) { if (Session["Login"] != null) { if (String.IsNullOrEmpty(model.EnergyName)) { ModelState.AddModelError("Energy Name", "Please Enter Energy Name"); } if (String.IsNullOrEmpty(model.EnergyCode)) { ModelState.AddModelError("Energy Code", "Please Enter Energy Code"); } if (ModelState.IsValid) { try { LoginSession loginsession = (LoginSession)Session["Login"]; model.CreateBy = Convert.ToInt64(loginsession.UserID); if (EnergyModel.CreateEnergy(model)) { return Json(new { result = 1, message = "Record was successfully Saved!" }); } else { return Json(new { result = 0, message = "Duplicate Notification Name " }); } } catch (Exception ex) { return Json(new { result = 0, message = "ErrorMessage" + ":" + ex.StackTrace.ToString() }); } } else { String errorMessage = String.Empty; String exception = String.Empty; foreach (var modelStateVal in ViewData.ModelState.Values) { foreach (var error in modelStateVal.Errors) { errorMessage = error.ErrorMessage; exception = error.Exception.ToString(); } } return Json(new { result = 0, message = "ErrorMessage" + ":" + exception }); } } else { return RedirectToAction("Index", "Home"); } }
public Object EditRecord(Int64 EnergyID) { EnergyMaster _energy = new EnergyMaster(); try { Energy energy = DAL.DALEnergy.EditEnergy(Convert.ToInt32(EnergyID)); _energy.ID = energy.ID; if (!String.IsNullOrEmpty(energy.EnergyName)) { _energy.EnergyName = energy.EnergyName; } if (!String.IsNullOrEmpty(energy.EnergyCode)) { _energy.EnergyCode = energy.EnergyCode; } } catch (Exception ex) { throw; } return _energy; }
public static bool UpdateEnergy(EnergyMaster energy) { Boolean flag = false; try { Icontext objinter = new BALEnergy(); flag = objinter.UpdateRecord(energy); } catch (Exception ex) { throw; } return flag; }
public ActionResult Edit(String EnergyID) { if (Session["Login"] != null) { LoginSession loginsession = (LoginSession)Session["Login"]; ViewBag.CompanyLogo = loginsession.CompanyLogo; ViewBag.Layout1 = BAL.Common.LayoutType(loginsession.UserType); String actionName = this.ControllerContext.RouteData.Values["action"].ToString(); String controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); ViewBag.Menu = BAL.Common.GetActiveMenu(controllerName, actionName, BAL.Common.LayoutType(loginsession.UserType)); ViewBag.RoleName = loginsession.RoleName; if (EnergyID != null) { String Dec_EnergyID = BAL.Security.URLDecrypt(EnergyID); if ((Dec_EnergyID != "0") && (Dec_EnergyID != null)) { EnergyMaster energy = new EnergyMaster(); try { energy = BAL.EnergyModel.EditEnergy(Dec_EnergyID); ViewBag.EnergyID = energy.ID; } catch (Exception ex) { return Content(ex.Message); } return View(energy); } } { return RedirectToAction("Index", "Energy"); } } else { return RedirectToAction("Index", "Home"); } }
public ActionResult Update(EnergyMaster model) { if (Session["Login"] != null) { if (String.IsNullOrEmpty(model.EnergyName)) { ModelState.AddModelError("Energy Name", "Please Enter Energy Name"); } if (String.IsNullOrEmpty(model.EnergyCode)) { ModelState.AddModelError("Energy Code", "Please Enter Energy Code"); } if (ModelState.IsValid) { try { LoginSession loginsession = (LoginSession)Session["Login"]; model.modifyBy = Convert.ToInt64(loginsession.UserID); if (EnergyModel.UpdateEnergy(model)) { return RedirectToAction("Index", "Energy"); } else { return Content("Unable to save , try again"); } } catch (Exception ex) { return Content("ErrorMessage" + ":" + ex.StackTrace.ToString()); } } else { return RedirectToAction("Index", "Energy"); } } else { return RedirectToAction("Index", "Home"); } }