public ActionResult CreateArea(AreasInfoVM iViewModel) { ActionResult oResponse = null; //verify high enough Access level if (Session["UserName"] != null && (int)Session["Role"] != 1) { if (ModelState.IsValid) { try { //map data from PO to DO IAreaInfoDO lAreaForm = Map.MapAreaPOtoDO(iViewModel.Area); //call DataAccess method for inserting new row, passing the completed forms values AreaData.InsertArea(lAreaForm); } catch (Exception ex) { //catch, log, store error message using (StreamWriter fileWriter = new StreamWriter(@"C:\Users\Lukus\Documents\BootCamp\Projects\Visual Studio\RunescapeMVC\ErrorLogs\Logs.txt")) { fileWriter.WriteLine("{0}-{1}", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.Message, true); } iViewModel.ErrorMessage = "We apologize, but we were unable to handle your request."; } finally { //If null, then there was no error if (iViewModel.ErrorMessage == null) { //Display areas if there was no error oResponse = RedirectToAction("ViewAllAreas", "Areas"); } //If not null, there WAS an error else { //if error occurred, redirect back to form, keeping users data input oResponse = View(iViewModel); } } } else { oResponse = View(iViewModel); } } else { //redirect to homepage if role is 1 or guest oResponse = RedirectToAction("Index", "Home"); } return(oResponse); }
public ActionResult UpdateArea(AreasInfoVM iViewModel) { ActionResult oResponse = null; if (Session["UserName"] != null && (int)Session["Role"] != 1) { if (ModelState.IsValid) { try { IAreaInfoDO lAreaForm = Map.MapAreaPOtoDO(iViewModel.Area); //call method from DAL to update database AreaData.UpdateArea(lAreaForm); oResponse = RedirectToAction("ViewAllAreas", "Areas"); } catch (Exception ex) { //write ex.message to log file using (StreamWriter fileWriter = new StreamWriter(@"C:\Users\Lukus\Documents\BootCamp\Projects\Visual Studio\RunescapeMVC\ErrorLogs\Logs.txt")) { fileWriter.WriteLine("{0}-{1}", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.Message, true); } iViewModel.ErrorMessage = "Sorry, something went wrong. Please try again."; oResponse = View(iViewModel); } finally { } } else { oResponse = View(iViewModel); } } else { oResponse = RedirectToAction("Index", "Home"); } return(oResponse); }
public ActionResult UpdateArea(long areaID) { ActionResult oResponse = null; //verifiy user role to be high enough if (Session["UserName"] != null && (int)Session["Role"] != 1) { AreasInfoVM areaInfoVM = new AreasInfoVM(); IAreaInfoDO areaDO = AreaData.ViewAreaByID(areaID); areaInfoVM.Area = Map.MapAreaDOtoPO(areaDO); oResponse = View(areaInfoVM); } else { oResponse = RedirectToAction("Index", "Home"); } return(oResponse); }