///<summary> /// Sends request to database for creating a new team /// </summary> public ActionResult AddTeam(TeamViewModel iViewModel) { ActionResult oResponse = null; var userPO = (IUserPO)Session["UserModel"]; // Ensure user is authenticated if (userPO.Email != null && userPO.RoleID_FK == (int)RoleEnum.Administrator) { if (ModelState.IsValid) { try { // Map Team properties from presentation to data objects ITeamDO lTeamForm = TeamMapper.MapTeamPOtoDO(iViewModel.Team); // Passes form to AddTeam method _TeamDataAccess.CreateNewTeam(lTeamForm, userPO.UserID); oResponse = RedirectToAction("ViewAllTeams", "Maint"); } catch (Exception ex) { ErrorLogger.LogError(ex, "AddTeam", "Maint"); iViewModel.ErrorMessage = "There was an issue adding a new team. Please try again. If the problem persists contact your IT department."; oResponse = View(iViewModel); } } else { oResponse = View(iViewModel); } } else { // User doesn't have access oResponse = RedirectToAction("Index", "Home"); } return(oResponse); }
///<summary> /// Updates information for a team /// </summary> public ActionResult UpdateTeamInformation(TeamViewModel iTeam) { ActionResult oResponse = null; var userPO = (IUserPO)Session["UserModel"]; iTeam.User.Email = userPO.Email; iTeam.User.RoleID_FK = userPO.RoleID_FK; // Ensure user is authenticated if (userPO.Email != null && userPO.RoleID_FK == (int)RoleEnum.Administrator) { if (ModelState.IsValid) { try { // Map team from presentation to data objects ITeamDO lTeamForm = TeamMapper.MapTeamPOtoDO(iTeam.Team); // Passes form to be updated _TeamDataAccess.UpdateTeam(lTeamForm, userPO.UserID); oResponse = RedirectToAction("ViewAllTeams", "Maint"); } catch (Exception ex) { ErrorLogger.LogError(ex, "UpdateTeamInformation", "Maint"); iTeam.ErrorMessage = "There was an issue with updating the selected team. Please try again. If the problem persists contact your IT team."; oResponse = View(iTeam); } } else { oResponse = View(iTeam); } } return(oResponse); }