public ActionResult Register(UserVM iUser) { ActionResult oResponse = null; if (ModelState.IsValid) //if info correct { try { //Maping assigned into a variable IUserDO Userform = UserMap.MapPOtoDO(iUser.User); //Method used from DAL UserAccess.Register(Userform); //Return to login view oResponse = RedirectToAction("Login", "User"); } catch (Exception e) { iUser.ErrorMessage = "Sorry we can preform that task at the moment, try again later"; ErrorLog.LogError(e); oResponse = View(iUser); } finally { //Onshore standards } } else //if incorrect info { oResponse = View(iUser); } return(oResponse); }
public ActionResult UpdateUser(UserVM changeUser) { ActionResult oResult = null; if (Session["UserName"] != null && (int)Session["UserLevel"] == 1) { //if the info was entered as required if (ModelState.IsValid) { try { IuserInfoDO updateUser = UserMap.MapPOtoDO(changeUser.User); //call to producer data access method _UserAccess.UpdateUser(updateUser); } catch (Exception e) { //what to do with exception, what to write if (e.Message.Contains("duplicate")) { changeUser.ErrorMessage = "Unable to process request, duplicate record already exists"; } else { changeUser.ErrorMessage = "We apologize but we were unable to handle your request at this time."; } } finally { } if (changeUser.ErrorMessage == null) { //if no errors take them to producer list to see if their submission was added oResult = RedirectToAction("ViewUsers", "User"); } else { //if any errors caught then redirect to screen to change producer info, same as they came from oResult = View(changeUser); } } else { oResult = View(changeUser); } } else { oResult = RedirectToAction("Login", "User"); } return(oResult); }
public ActionResult AddUser(UserVM viewModel) { ActionResult oResponse = null; if (ModelState.IsValid) { try { IuserInfoDO userform = UserMap.MapPOtoDO(viewModel.User); //call to User DAL for method _UserAccess.InsertUser(userform); //set tempdata to hold registered info for login screen TempData["UserName"] = userform.UserName; TempData["Password"] = userform.Password; } catch (Exception e) { if (e.Message.Contains("duplicate")) { //if duplicate user name is found, give user this msg viewModel.ErrorMessage = String.Format("There is already a {0} in the database.", viewModel.User.UserName); } else { //all other errors return this msg to user viewModel.ErrorMessage = "We apologize but we were unable to handle your request at this time."; } } finally { //nothing to do here } if (viewModel.ErrorMessage == null) { oResponse = RedirectToAction("Login", "User"); } else { oResponse = View(viewModel); } } else { oResponse = View(viewModel); } return(oResponse); }
public ActionResult UpdateUser(UserVM iUser) { ActionResult oResponse = null; if (Session["Username"] == null || (Int16)Session["Role"] == 3) { //Guest, User oResponse = RedirectToAction("Index", "Home"); } else //Admin { if (ModelState.IsValid) //if correct info { try { //give mapping a variable to be used IUserDO update = UserMap.MapPOtoDO(iUser.User); //Call the method to be used UserAccess.UpdateUser(update); if ((Int16)Session["Role"] != 1) { //if not admin //redirect to profile oResponse = RedirectToAction("ViewUserbyID", "User", new { UserID = (long)Session["UserID"] }); //Return to the view to see changes } else { //admin views all users oResponse = RedirectToAction("ViewUsers", "User"); } } catch (Exception e) { //for the errors thrown below iUser.ErrorMessage = "Sorry your request cannot be processed"; ErrorLog.LogError(e); oResponse = View(iUser); } finally { //Onshore standards } } else //if it isn't valid information { oResponse = View(iUser); //Return to the Update page to fill out info again } } return(oResponse); }
public ActionResult CreateUser(UserVM iUser) { ActionResult oResponse = null; if (Session["Username"] == null || (Int16)Session["Role"] != 1) { //Guest,Power User, User oResponse = RedirectToAction("Index", "Home"); } else { //Admin if (ModelState.IsValid) //if info correct { try { //Mapping assigned to variable IUserDO Userform = UserMap.MapPOtoDO(iUser.User); //Use of method from DAL UserAccess.CreateUser(Userform); //Redirect to list of users oResponse = RedirectToAction("ViewUsers", "User", new { UserID = Session["UserID"] }); } catch (Exception e) { iUser.ErrorMessage = "Sorry we can preform that task at the moment, try again later"; ErrorLog.LogError(e); oResponse = View(iUser); } finally { //Onshore standards } } else //if info incorrect { oResponse = View(iUser); } } return(oResponse); }