//public TeamDataAccess(string connString) //{ // conString = connString; //} //CREATe public bool CreateNewTeam(ITeamDO newTeam, int userID) { bool result = false; try { using (SqlConnection con = new SqlConnection(conString)) { using (SqlCommand com = new SqlCommand("sp_TeamAddNew", con)) { com.CommandType = CommandType.StoredProcedure; com.CommandTimeout = 35; com.Parameters.Add(new SqlParameter("@TeamName", newTeam.Name)); com.Parameters.Add(new SqlParameter("@Comment", newTeam.Comment)); com.Parameters.Add(new SqlParameter("@CreatedUser", userID)); con.Open(); com.ExecuteNonQuery(); result = true; } } } catch (Exception ex) { ErrorLogger.LogError(ex, "CreateTeams", "nothing"); } return(result); }
public static TeamPO MapTeamDOtoPO(ITeamDO teamDO) { var oTeam = new TeamPO(); oTeam.TeamID = teamDO.TeamID; oTeam.Name = teamDO.Name; oTeam.Comment = teamDO.Comment; oTeam.Active = teamDO.Active; oTeam.RunningTotal = teamDO.RunningTotal; return(oTeam); }
///<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); }
//UPDATE public string UpdateTeam(ITeamDO newTeam, int userID) { string result; try { using (SqlConnection con = new SqlConnection(conString)) { using (SqlCommand com = new SqlCommand("sp_TeamUpdate", con)) { try { com.CommandType = CommandType.StoredProcedure; com.CommandTimeout = 35; com.Parameters.Add(new SqlParameter("@TeamID", newTeam.TeamID)); com.Parameters.Add(new SqlParameter("@TeamName", newTeam.Name)); com.Parameters.Add(new SqlParameter("@Comment", newTeam.Comment)); com.Parameters.Add(new SqlParameter("@UpdatedUser", userID)); com.ExecuteNonQuery(); result = "Success"; } catch (Exception ex) { ErrorLogger.LogError(ex, "UpdateTeams", "nothing"); result = "fail"; } } } } catch (Exception e) { ErrorLogger.LogError(e, "UpdateTeams", "nothing"); result = "fail"; } return(result); }
// TODO: Rename and add switch/case for role decisions private void AssociateAdminValues(AbsenceViewModel selectedTeamAbsences, List <Tuple <string, decimal> > teamRanker, ITeamDO teamName, Tuple <string, decimal> bestStandingTeam, Tuple <string, decimal> bottomStandingTeam, Tuple <string, decimal> topEmployee) { foreach (var item in teamRanker) { selectedTeamAbsences.TeamRanker.Team.Name = item.Item1; selectedTeamAbsences.TeamRanker.Absence.Point = item.Item2; } selectedTeamAbsences.Team.Name = teamName.Name; selectedTeamAbsences.TopTeam.Team.Name = bestStandingTeam.Item1; selectedTeamAbsences.TopTeam.Absence.RunningTotal = bestStandingTeam.Item2; selectedTeamAbsences.BottomTeam.Team.Name = bottomStandingTeam.Item1; selectedTeamAbsences.BottomTeam.Absence.RunningTotal = bottomStandingTeam.Item2; selectedTeamAbsences.TopEmployee.User.Employee = topEmployee.Item1; selectedTeamAbsences.TopEmployee.Absence.Point = topEmployee.Item2; }