public TeamViewModel GetTeamById(int teamId) { var team = new TeamViewModel(); try { var teamResult = this._dbContext.Team.Include("TeamMembers").FirstOrDefault(w => w.TeamId == teamId); if (teamResult != null) { ; } return(TeamMapper.ToTeamModel(teamResult)); } catch (System.Exception) { throw; } }
public async Task <ActionResult <TeamDto> > Add(string displayName) { Team newTeam = new Team() { DisplayName = displayName }; await _unitOfWork.TeamRepository.AddAsync(newTeam); await _unitOfWork.SaveChangesAsync(); return(CreatedAtAction( nameof(GetById), new { id = newTeam.Id }, TeamMapper.MapToDto(newTeam))); }
private Resource GetPlayerResource(Player player) { var playerResource = new PlayerMapper(UriHelper).Map( player, PlayerMapper.Name, PlayerMapper.Age, PlayerMapper.PreferredPosition, PlayerMapper.CurrentPosition, PlayerMapper.Rating, PlayerMapper.Skills); // Team. if (player.Team != null) { var teamResource = new TeamMapper(UriHelper).Map(player.Team, TeamMapper.TeamName); playerResource.AddResource("rel:team", teamResource); } return(playerResource); }
public List <TeamListModel> GetAllTeamsForUser(int id) { using (var dbContext = dbContextFactory.CreateDbContext()) { var userMapper = new UserMapper(); var teamMapper = new TeamMapper(); var teamEntityList = GetAllDetail(); var userTeamList = new List <TeamListModel>(); var repository = new UserRepository(dbContextFactory); var user = userMapper.DetailModelToListModel(repository.GetById(id)); foreach (var team in teamEntityList) { if (team.Members.Contains(user)) { userTeamList.Add(teamMapper.DetailModelToListModel(team)); } } return(userTeamList); } }
///<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); }
public void Verify_MapToEntity_WithExistingEntity_AssignsTeamProperties() { // Arrange var mapper = new TeamMapper(); var model = TeamsMockingSetup.DoMockingSetupForTeamModel(); // Act ITeam existingEntity = new Team { Id = 1 }; mapper.MapToEntity(model.Object, ref existingEntity); // Assert // <None> // Related Objects Assert.Equal(model.Object.PrimaryImageFileId, existingEntity.PrimaryImageFileId); Assert.Equal(model.Object.FirstIssueAppearanceId, existingEntity.FirstIssueAppearanceId); Assert.Equal(model.Object.PublisherId, existingEntity.PublisherId); // Associated Objects model.VerifyGet(x => x.TeamAliases, Times.Once); //Assert.Equal(model.Object.TeamAliases?.Count, existingEntity.TeamAliases?.Count); model.VerifyGet(x => x.TeamCharacterEnemies, Times.Once); //Assert.Equal(model.Object.TeamCharacterEnemies?.Count, existingEntity.TeamCharacterEnemies?.Count); model.VerifyGet(x => x.TeamCharacterFriends, Times.Once); //Assert.Equal(model.Object.TeamCharacterFriends?.Count, existingEntity.TeamCharacterFriends?.Count); model.VerifyGet(x => x.TeamIssuesAppearedIn, Times.Once); //Assert.Equal(model.Object.TeamIssuesAppearedIn?.Count, existingEntity.TeamIssuesAppearedIn?.Count); model.VerifyGet(x => x.TeamIssuesDisbandedIn, Times.Once); //Assert.Equal(model.Object.TeamIssuesDisbandedIn?.Count, existingEntity.TeamIssuesDisbandedIn?.Count); model.VerifyGet(x => x.TeamIssues, Times.Once); //Assert.Equal(model.Object.TeamIssues?.Count, existingEntity.TeamIssues?.Count); model.VerifyGet(x => x.TeamMembers, Times.Once); //Assert.Equal(model.Object.TeamMembers?.Count, existingEntity.TeamMembers?.Count); model.VerifyGet(x => x.TeamMovies, Times.Once); //Assert.Equal(model.Object.TeamMovies?.Count, existingEntity.TeamMovies?.Count); model.VerifyGet(x => x.TeamStoryArcs, Times.Once); //Assert.Equal(model.Object.TeamStoryArcs?.Count, existingEntity.TeamStoryArcs?.Count); model.VerifyGet(x => x.TeamVolumes, Times.Once); //Assert.Equal(model.Object.TeamVolumes?.Count, existingEntity.TeamVolumes?.Count); }
///<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); }
///<summary> /// Views all teams(admin) /// </summary> public ActionResult TestViews() { ActionResult oResponse = null; var ViewAllTeamsVM = new TeamViewModel(); var userPO = (IUserPO)Session["UserModel"]; // Ensures authenticated if (userPO.Email != null && userPO.RoleID_FK == (int)RoleEnum.Administrator) { try { // Test for retrieves var allTeams = _TeamDataAccess.GetAllTeams(); var allSMTeams = _TeamDataAccess.GetAllSMTeams(); var team = _TeamDataAccess.GetTeamNameByID(5); var allSMTeamAbsences = _TeamDataAccess.GetAllSMTeamsByUserID(8); var viewUserAbsence = PointsDataAccess.GetAbsenceByID(4); var viewAllAbsences = PointsDataAccess.ViewAllAbsences(); var teamAbsences = PointsDataAccess.GetAbsencesByTeamID(5); var viewUserAbsences = PointsDataAccess.ViewAbsencesByUserID(8); // Maps from data objects to presentation objects. ViewAllTeamsVM.ListOfPos = TeamMapper.MapListOfDOsToListOfPOs(allTeams); oResponse = View(ViewAllTeamsVM); } catch (Exception ex) { ErrorLogger.LogError(ex, "ViewAllTeams", "Maint"); ViewAllTeamsVM.ErrorMessage = ""; // TODO: Add meaningful front end message } } else { oResponse = RedirectToAction("Index", "Home"); } return(oResponse); }
public TeamDetailModel AddMember(TeamDetailModel teamModel, UserDetailModel userModel) { using (var dbContext = _dbContextFactory.CreateTeamChatDbContext()) { var userEntity = dbContext.Users .Include(tu => tu.Teams) .ThenInclude(u => u.User) .Include(tu => tu.Teams) .ThenInclude(t => t.Team) .Include(u => u.Activities) .First(u => u.Id == userModel.Id); var teamEntity = dbContext.Teams .Include(tu => tu.Members) .ThenInclude(t => t.Team) .Include(tu => tu.Members) .ThenInclude(u => u.User) .Include(t => t.Posts) .ThenInclude(c => c.Comments) .First(t => t.Id == teamModel.Id); var junction = new TeamUser { Team = teamEntity, TeamId = teamEntity.Id, User = userEntity, UserId = userEntity.Id }; userEntity.Teams.Add(junction); teamEntity.Members.Add(junction); dbContext.TeamUsers.Add(junction); dbContext.Users.Update(userEntity); dbContext.Teams.Update(teamEntity); dbContext.SaveChanges(); return(TeamMapper.MapToDetailModel(teamEntity)); } }
public void GetAllTeamsCorrect() { var teams = new List <Team>(); teams.Add(new Team { Id = 1, Naam = "Team A" }); IQueryable <Team> queryableTeams = teams.AsQueryable(); var teamsDTO = new List <TeamDTO>(); foreach (var team in teams) { teamsDTO.Add(TeamMapper.MapTeamModelToTeamDTO(team)); } //Arange var teamRepo = new Mock <ISQLRepository <Team> >(); teamRepo.Setup(x => x.GetAll()).Returns(queryableTeams); var teamService = new TeamService(teamRepo.Object); //Act var allTeams = teamService.GetAllTeams(); //Assert Assert.That(allTeams.Count(), Is.EqualTo(teamsDTO.Count())); for (int i = 0; i < allTeams.Count(); i++) { Assert.That(allTeams.ToArray()[i].Id, Is.EqualTo(teamsDTO.ToArray()[i].Id)); Assert.That(allTeams.ToArray()[i].Naam, Is.EqualTo(teamsDTO.ToArray()[i].Naam)); } }
private bool LoadTeams(string team1Name, string team2Name) { bool result = true; var teams = CSVParser.ParseCsvFile <TeamEntity>(Constants.TEAMS_FILE); Team1 = teams.Select(x => TeamMapper.Map(x)).Where(t => t.TeamName.Equals(team1Name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); Team2 = teams.Select(x => TeamMapper.Map(x)).Where(t => t.TeamName.Equals(team2Name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (Team1 == null) { Logger.Error("Failed to find team with name: " + team1Name); result = false; } if (Team2 == null) { Logger.Error("Failed to find team with name: " + team2Name); result = false; } return(result); }
private static void AddMatchData(List <Match> matches, RiotDataContext riotDb) { Console.WriteLine("Updating {0} matches.", matches.Count()); foreach (var match in matches) { var matchData = RiotService.MatchService(match.MatchId); var currentMatch = riotDb.Matches.First(m => m.MatchId == match.MatchId); currentMatch.AddMatchData(matchData); foreach (var participant in matchData.Participants) { var stats = StatisticsMapper.MapParticipantStat(participant.Statistics); currentMatch.Participants.Add(ParticipantMapper.MapParticipant(matchData, participant, stats)); } foreach (var team in matchData.Teams) { currentMatch.Teams.Add(TeamMapper.MapTeam(team)); } riotDb.SubmitChanges(); } }
public IList <TeamRating> GetTeamRatings() { SqlConnection connection = new SqlConnection(_connectionString); connection.Open(); SqlTransaction transaction = connection.BeginTransaction(); // attempt to get the rankings data from the db TeamRatingGateway trGateway = new TeamRatingGateway(connection, transaction); TeamGateway teamGateway = new TeamGateway(connection, transaction); LeagueGateway leagueGateway = new LeagueGateway(connection, transaction); var teamRankings = trGateway.GetCurrentTeamRatings(); if (!teamRankings.Any() || DateTime.Now.Subtract(teamRankings[0].AddedDate).TotalDays > 30) { var teams = teamGateway.GetAllWftdaTeams(); var leagues = leagueGateway.GetAllLeagues(); var teamMapper = new TeamMapperGateway(connection, transaction).GetAllTeamMappers(); var wftdaData = GetWftdaRankingsData(); var ftsData = GetFtsRankingsData(); teamRankings = new List <TeamRating>(250); var leftOut = new List <WftdaRankingData>(); foreach (WftdaRankingData wftda in wftdaData) { var fts = ftsData.FirstOrDefault(f => string.Equals(wftda.TeamName.Substring(0, 10), f.TeamName.Substring(0, 10), StringComparison.OrdinalIgnoreCase)); if (fts != null) { teamRankings.Add(new TeamRating { FtsRank = fts.Rank, FtsScore = fts.Rating, TeamID = 0, TeamName = wftda.TeamName, WftdaRank = wftda.Rank, WftdaScore = wftda.RatingScore, WftdaStrength = wftda.Strength }); } else { // try the team mapper? TeamMapper map = teamMapper.FirstOrDefault(tm => string.Equals(tm.TeamSpelling, wftda.TeamName, StringComparison.OrdinalIgnoreCase)); if (map != null) { var otherMaps = teamMapper.Where(tm => tm.TeamID == map.TeamID).Select(tm => tm.TeamSpelling); fts = ftsData.FirstOrDefault(f => otherMaps.Contains(f.TeamName)); if (fts != null) { teamRankings.Add(new TeamRating { FtsRank = fts.Rank, FtsScore = fts.Rating, TeamID = map.TeamID, TeamName = wftda.TeamName, WftdaRank = wftda.Rank, WftdaScore = wftda.RatingScore, WftdaStrength = wftda.Strength }); } else { leftOut.Add(wftda); } } } } List <TeamRating> leftOvers = new List <TeamRating>(); foreach (TeamRating teamRating in teamRankings) { if (teamRating.TeamID > 0) { continue; } var team = teams.FirstOrDefault(t => string.Equals(t.Name, teamRating.TeamName, StringComparison.OrdinalIgnoreCase)); if (team != null) { teamRating.TeamID = team.ID; } else { var league = leagues.FirstOrDefault(l => string.Equals(l.Name, teamRating.TeamName, StringComparison.OrdinalIgnoreCase)); if (league != null) { team = teams.First(t => t.LeagueID == league.ID); teamRating.TeamID = team.ID; } else { // try the team mapper? TeamMapper map = teamMapper.FirstOrDefault(tm => string.Equals(tm.TeamSpelling, teamRating.TeamName, StringComparison.OrdinalIgnoreCase)); if (map != null) { teamRating.TeamID = map.TeamID; } // TODO: else, create the League and the team? The nature of leagueID makes that tough... } } } trGateway.InsertTeamRatings(teamRankings.Where(tr => tr.TeamID != 0).ToList()); } transaction.Commit(); connection.Close(); return(teamRankings); }
public void Verify_AreEqual_WithEqualObjects_ReturnsTrue() { // Arrange var mapper = new TeamMapper(); var model = TeamsMockingSetup.DoMockingSetupForTeamModel(1); var entity = TeamsMockingSetup.DoMockingSetupForTeam(1); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.True(result); }
public TeamRepository(DatabaseConnection context) { this.context = context; this.mapper = new TeamMapper(); }
public override void CreateMapper() { Mapper = new TeamMapper(); }
public void TeamRepozitoryTest() { var dbContextFactory = new InMemoryDbContextFactory(); var Repository = new TeamRepository(dbContextFactory); var UserRepository = new UserRepository(dbContextFactory); Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(0)); var Post = new PostModel() { Id = 1, Author = 4, Comments = new Collection <CommentModel>(), Date = new DateTime(2019, 1, 4), Team = 2, Text = "No pozrite sa na tie komenty", Title = "Lol" }; var Comment1 = new CommentModel() { Author = 2, Date = new DateTime(2019, 1, 4), Id = 11, Text = "Testovaci koment", Post = 1 }; var Comment2 = new CommentModel() { Author = 1, Date = new DateTime(2019, 1, 5), Id = 20, Text = "Testovaci koment cislo 2", Post = 1 }; Post.Comments.Add(Comment1); Post.Comments.Add(Comment2); var User1 = new UserDetailModel() { Id = 4, Name = "Anton", Comments = new Collection <CommentModel>(), Email = "*****@*****.**", Password = "******", Posts = new Collection <PostModel>() }; var User2 = new UserDetailModel() { Id = 2, Name = "Tomas", Email = "*****@*****.**", Password = "******", Comments = new Collection <CommentModel>(), Posts = new Collection <PostModel>() }; var User3 = new UserDetailModel() { Id = 3, Name = "Sergej", Email = "*****@*****.**", Password = "******", Comments = new Collection <CommentModel>(), Posts = new Collection <PostModel>() }; var Team1 = new TeamDetailModel() { Id = 2, Leader = User2.Id, Members = new Collection <UserListModel>(), Name = "Team1", }; var Team2 = new TeamDetailModel() { Id = 3, Leader = User3.Id, Members = new Collection <UserListModel>(), Name = "Team2", }; UserRepository.Create(User1); UserRepository.Create(User2); UserRepository.Create(User3); var userMapper = new UserMapper(); Team1.Members.Add(userMapper.DetailModelToListModel(User1)); Team1.Members.Add(userMapper.DetailModelToListModel(User2)); Team2.Members.Add(userMapper.DetailModelToListModel(User2)); Team2.Members.Add(userMapper.DetailModelToListModel(User3)); Repository.Create(Team1); Repository.Create(Team2); var ReceivedTeam = Repository.GetById(2); Assert.Equal(Team1, ReceivedTeam); ReceivedTeam = Repository.GetById(3); Assert.Equal(Team2, ReceivedTeam); var AllTeams = new List <TeamListModel>(); var AllTeamsDetail = new List <TeamDetailModel>(); var ReceivedAllTeams = Repository.GetAll(); var ReceivedAllTeamsDetail = Repository.GetAllDetail(); var teamMapper = new TeamMapper(); AllTeams.Add(teamMapper.DetailModelToListModel(Team1)); AllTeams.Add(teamMapper.DetailModelToListModel(Team2)); AllTeamsDetail.Add(Team1); AllTeamsDetail.Add(Team2); var Comparer = new CollectionComparer <TeamListModel>(); Assert.True(Comparer.Equals(AllTeams, ReceivedAllTeams)); var DetailComparer = new CollectionComparer <TeamDetailModel>(); Assert.True(DetailComparer.Equals(AllTeamsDetail, ReceivedAllTeamsDetail)); var AllTeamsForUser1 = new List <TeamListModel>(); AllTeamsForUser1.Add(teamMapper.DetailModelToListModel(Team1)); var ReceivedAllTeamsForUser1 = Repository.GetAllTeamsForUser(User1.Id); Assert.True(Comparer.Equals(AllTeamsForUser1, ReceivedAllTeamsForUser1)); Team1.Name = "Zmenene meno"; Repository.Update(Team1); Assert.Equal(Team1, Repository.GetById(Team1.Id)); Repository.Delete(3); Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(0)); ReceivedTeam = Repository.GetById(2); Assert.Equal(Team1, ReceivedTeam); }
//[ValidateAntiForgeryToken] ///<summary> /// Admin view all absences by all employees /// </summary> /// <returns></returns> public ActionResult ViewAllAbsenceEntries() { ActionResult oResponse = null; var userPO = (IUserPO)Session["UserModel"]; var viewAllAbsenceEntries = new AbsenceViewModel(); // User can view all absences if Admin if (userPO.Email != null && userPO.RoleID_FK == (int)RoleEnum.Administrator) { try { // Calls to retrieve all absences from data access var allAbsences = PointsDataAccess.ViewAllAbsences(); var allTeams = _TeamDataAccess.GetAllTeams(); // Retrieve widget values var bestStandingTeam = _TeamBusinessLogic.QueryBestStandingTeam(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences); var bottomStandingTeam = _TeamBusinessLogic.QueryWorstStandingTeam(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences); var teamRanker = _TeamBusinessLogic.QueryTeamRanker(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences); foreach (var item in teamRanker) { viewAllAbsenceEntries.TeamRanker.Team.Name = item.Item1; viewAllAbsenceEntries.TeamRanker.Absence.RunningTotal = item.Item2; } AssociateAdminValues(viewAllAbsenceEntries, bestStandingTeam, bottomStandingTeam, allAbsences); viewAllAbsenceEntries.User.RoleID_FK = userPO.RoleID_FK; viewAllAbsenceEntries.User.Email = userPO.Email; oResponse = View(viewAllAbsenceEntries); } catch (Exception ex) { ErrorLogger.LogError(ex, "ViewAllAbsenceEntries", "Maint"); viewAllAbsenceEntries.ErrorMessage = "Something went wrong retrieving the list of absences. Please try again."; oResponse = View(viewAllAbsenceEntries); } } else { // State was invalid redirect home oResponse = RedirectToAction("Index", "Home"); } return(oResponse); }
public UserRepository(DatabaseConnection aContext) { context = aContext; userMapper = new UserMapper(); teamMapper = new TeamMapper(); }
public async Task <ActionResult <TeamDto[]> > Get() => (await _unitOfWork.TeamRepository .GetAllAsync()) .OrderBy(team => team.DisplayName) .Select(team => TeamMapper.MapToDto(team)) .ToArray();
public void Verify_MapToModel_AssignsTeamProperties() { // Arrange var mapper = new TeamMapper(); var entity = TeamsMockingSetup.DoMockingSetupForTeam(); // Act var model = mapper.MapToModel(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); Assert.Equal(entity.Object.FirstIssueAppearanceId, model.FirstIssueAppearanceId); Assert.Equal(entity.Object.PublisherId, model.PublisherId); // Associated Objects Assert.Equal(entity.Object.TeamAliases?.Count, model.TeamAliases?.Count); Assert.Equal(entity.Object.TeamCharacterEnemies?.Count, model.TeamCharacterEnemies?.Count); Assert.Equal(entity.Object.TeamCharacterFriends?.Count, model.TeamCharacterFriends?.Count); Assert.Equal(entity.Object.TeamIssuesAppearedIn?.Count, model.TeamIssuesAppearedIn?.Count); Assert.Equal(entity.Object.TeamIssuesDisbandedIn?.Count, model.TeamIssuesDisbandedIn?.Count); Assert.Equal(entity.Object.TeamIssues?.Count, model.TeamIssues?.Count); Assert.Equal(entity.Object.TeamMembers?.Count, model.TeamMembers?.Count); Assert.Equal(entity.Object.TeamMovies?.Count, model.TeamMovies?.Count); Assert.Equal(entity.Object.TeamStoryArcs?.Count, model.TeamStoryArcs?.Count); Assert.Equal(entity.Object.TeamVolumes?.Count, model.TeamVolumes?.Count); }
public Response GetItem(string gameId) { RequestHelper.ValidateId(gameId); var gameInfo = GetGameInfo(gameId); if (gameInfo.CurrentTeam == null) { throw ResponseHelper.Get501NotImplemented("You must pick a team now, but this is not implemented yet..."); } var halDocument = CreateHalDocument(UriHelper.GetGameUri(gameId), gameInfo); halDocument.AddLink("game-links", new Link(UriHelper.GetGameLinksUri(gameId))); // Add GameDateTime navigation. var gameDateTimeService = ServiceFactory.CreateGameDateTimeService(gameInfo); var now = gameDateTimeService.GetNow(); var currentGameDateTimeResource = new GameDateTimeMapper(UriHelper).Map(now); halDocument.AddResource("rel:game-datetime-navigation", currentGameDateTimeResource); // Add my team. var teamResource = new TeamMapper(UriHelper).Map(gameInfo.CurrentTeam, TeamMapper.TeamName, TeamMapper.Rating, TeamMapper.RatingGoalkeeper, TeamMapper.RatingDefence, TeamMapper.RatingMidfield, TeamMapper.RatingAttack, TeamMapper.RatingPercentage); halDocument.AddResource("rel:my-team", teamResource); // Add season resource. var seasonService = ServiceFactory.CreateSeasonService(gameInfo); var currentSeason = seasonService.GetCurrentSeason(); var seasonResource = new SeasonMapper(UriHelper).Map(currentSeason, SeasonMapper.SeasonShortName, SeasonMapper.SeasonLongName); bool endOfSeason = seasonService.DetermineSeasonEnded(currentSeason.Id); bool endSeasonNow = currentSeason.EndDateTime == now.DateTime; if (endOfSeason && endSeasonNow) { var form = new Form("end-season") { Action = UriHelper.GetSeasonUri(gameId, currentSeason.Id), Method = "post", Title = "END SEASON!" }; seasonResource.AddForm(form); } halDocument.AddResource("rel:current-season", seasonResource); // Add season team statistics. var statisticsService = ServiceFactory.CreateStatisticsService(gameInfo); var seasonTeamStatistics = statisticsService.GetSeasonTeamStatistics(currentSeason.Id, gameInfo.CurrentTeamId); var seasonTeamStatisticsResource = new SeasonTeamStatisticsMapper(UriHelper).Map(seasonTeamStatistics); halDocument.AddResource("rel:season-team-statistics", seasonTeamStatisticsResource); // Add next match day. var matchService = ServiceFactory.CreateMatchService(gameInfo); var nextMatchDate = matchService.GetNextMatchDate(currentSeason.Id); if (nextMatchDate.HasValue) { var matchDayResourceFactory = new MatchDayResourceFactory(UriHelper, gameId, nextMatchDate.Value); var matchDayResource = matchDayResourceFactory.Create(); // Add a resource for the match of the current team. var matchForCurrentTeam = matchService.GetByMatchDayAndTeam(nextMatchDate.Value, gameInfo.CurrentTeamId); if (matchForCurrentTeam != null) { var matchResource = new MatchMapper(UriHelper).Map( matchForCurrentTeam, MatchMapper.CompetitionName, MatchMapper.CompetitionType, MatchMapper.Date, MatchMapper.Round); var teamMapper = new TeamMapper(UriHelper); var homeTeamResource = teamMapper.Map(matchForCurrentTeam.HomeTeam, TeamMapper.TeamName, TeamMapper.LeagueName, TeamMapper.CurrentLeaguePosition); matchResource.AddResource("home-team", homeTeamResource); var awayTeamResource = teamMapper.Map(matchForCurrentTeam.AwayTeam, TeamMapper.TeamName, TeamMapper.LeagueName, TeamMapper.CurrentLeaguePosition); matchResource.AddResource("away-team", awayTeamResource); matchResource.AddResource("your-opponent", gameInfo.CurrentTeam.Equals(matchForCurrentTeam.HomeTeam) ? awayTeamResource : homeTeamResource); matchDayResource.AddResource("next-match", matchResource); } // Only add the play next match day form when the matches are right now. if (nextMatchDate.Value == now.DateTime) { var playNextMatchDayForm = matchDayResourceFactory.GetForm(); matchDayResource.AddForm(playNextMatchDayForm); } halDocument.AddResource("rel:next-match-day", matchDayResource); } // Add league table. var leagueTableService = ServiceFactory.CreateLeagueTableService(gameInfo); var leagueTable = leagueTableService.GetBySeasonAndCompetition(currentSeason.Id, gameInfo.CurrentTeam.CurrentLeagueCompetitionId); var leagueTableResource = new LeagueTableMapper(UriHelper).Map(leagueTable); leagueTableResource.AddLink("leaguetables", new Link(UriHelper.GetSeasonLeagueTablesUri(gameId, currentSeason.Id)) { Name = "all", Title = "All league tables" }); halDocument.AddResource("rel:leaguetable", leagueTableResource); var response = GetResponse(halDocument); return(response); }
public TeamEntity() { mapper = new TeamMapper(); }
public GameMapper() { teamMapper = new TeamMapper(); }
public ITeamModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(TeamMapper.MapToModel(TeamsRepository.Get(id))); }
//[ValidateAntiForgeryToken] ///<summary> /// Views all absences by for a given team(TL, SM, Admin) /// </summary> /// <returns></returns> public ActionResult ViewAbsencesByTeamID(int teamID) { ActionResult oResponse = null; var selectedTeamAbsences = new AbsenceViewModel(); var userPO = (IUserPO)Session["UserModel"]; if (userPO.Email != null && userPO.RoleID_FK <= (int)RoleEnum.Team_Lead && userPO.RoleID_FK >= (int)RoleEnum.Administrator) { if (ModelState.IsValid) { try { // Stores list of absences by TeamID var absences = PointsDataAccess.GetAbsencesByTeamID(teamID); var teamName = _TeamDataAccess.GetTeamNameByID(teamID); // Retrieve lists for LINQ queries var allAbsences = PointsDataAccess.ViewAllAbsences(); var allTeams = _TeamDataAccess.GetAllTeams(); var allUsers = _UserDataAccess.GetAllUsers(); var topMemeberBOs = UserMapper.MapListOfDOsToListOfBOs(allUsers); // LINQ Queries var bestStandingTeam = _TeamBusinessLogic.QueryBestStandingTeam(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences); var bottomStandingTeam = _TeamBusinessLogic.QueryWorstStandingTeam(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences); var topEmployee = _TeamBusinessLogic.QueryBestStandingEmployee(allTeams, allAbsences, allUsers); var teamRanker = _TeamBusinessLogic.QueryTeamRanker(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences); MapAdminObjects(selectedTeamAbsences, allTeams, absences); switch (userPO.RoleID_FK) { // Admin case 1: selectedTeamAbsences.ListOfPos = AbsenceMapper.MapListOfDOsToListOfPOs(absences); AssociateAdminValues(selectedTeamAbsences, teamRanker, teamName, bestStandingTeam, bottomStandingTeam, topEmployee); break; // Service Manager case 2: var teamAbsences = AbsenceMapper.MapListOfDOsToListOfPOs(absences); var smTeams = _TeamDataAccess.GetAllSMTeamsByUserID(userPO.UserID); selectedTeamAbsences.SMTeams = TeamMapper.MapListOfDOsToListOfPOs(smTeams); AssociateAdminValues(selectedTeamAbsences, teamRanker, teamName, bestStandingTeam, bottomStandingTeam, topEmployee); //selectedTeamAbsences.ListOfPos = teamAbsences; //selectedTeamAbsences.TopTeam.Team.Name = bestStandingTeam.Item1; //selectedTeamAbsences.TopTeam.Absence.Point = bestStandingTeam.Item2; //selectedTeamAbsences.BottomTeam.Team.Name = bottomStandingTeam.Item1; //selectedTeamAbsences.BottomTeam.Absence.Point = bottomStandingTeam.Item2; //selectedTeamAbsences.TopEmployee.Name = topEmployee.Item1; //selectedTeamAbsences.TopEmployee.Absence.Point = topEmployee.Item2; //MapServiceManagerObjects(selectedTeamAbsences, allTeams, absences); //AssociateServiceManagerObjects(selectedTeamAbsences, topEmployee); oResponse = View(selectedTeamAbsences); break; // Team Lead case 3: var tlAbsences = AbsenceMapper.MapListOfDOsToListOfPOs(absences); selectedTeamAbsences.ListOfPos = tlAbsences; AssociateAdminValues(selectedTeamAbsences, teamRanker, teamName, bestStandingTeam, bottomStandingTeam, topEmployee); //selectedTeamAbsences.TopTeam.Team.Name = bestStandingTeam.Item1; //selectedTeamAbsences.TopTeam.Absence.Point = bestStandingTeam.Item2; //selectedTeamAbsences.BottomTeam.Team.Name = bottomStandingTeam.Item1; //selectedTeamAbsences.BottomTeam.Absence.Point = bottomStandingTeam.Item2; //selectedTeamAbsences.TopEmployee.Name = topEmployee.Item1; //selectedTeamAbsences.TopEmployee.Absence.Point = topEmployee.Item2; oResponse = View(selectedTeamAbsences); break; default: break; } oResponse = View(selectedTeamAbsences); } catch (Exception ex) { ErrorLogger.LogError(ex, "ViewAbsencesByTeamID", "Maint"); selectedTeamAbsences.ErrorMessage = "Something went wrong retrieving the list of absences. Please try again."; oResponse = View(selectedTeamAbsences); } } else { oResponse = View(selectedTeamAbsences); } } return(oResponse); }
public ITeamModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(TeamMapper.MapToModel(TeamsRepository.Get(key))); }
public void Verify_MapToModelLite_AssignsLiteOnlyTeamProperties() { // Arrange var mapper = new TeamMapper(); var entity = TeamsMockingSetup.DoMockingSetupForTeam(); // Act var model = mapper.MapToModelLite(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); Assert.Equal(entity.Object.FirstIssueAppearanceId, model.FirstIssueAppearanceId); Assert.Equal(entity.Object.PublisherId, model.PublisherId); }
public TeamController(ITeamService teamService) { _teamService = teamService; _teamMapper = new TeamMapper(); }
public void Verify_MapToSearchModel_AssignsTeamSearchProperties() { // Arrange var mapper = new TeamMapper(); var model = TeamsMockingSetup.DoMockingSetupForTeamModel(); // Act var searchModel = mapper.MapToSearchModel(model.Object); // Assert Assert.Equal(model.Object.PrimaryImageFileId, searchModel.PrimaryImageFileId); Assert.Equal(model.Object.PrimaryImageFile?.CustomKey, searchModel.PrimaryImageFileCustomKey); Assert.Equal(model.Object.PrimaryImageFile?.ApiDetailUrl, searchModel.PrimaryImageFileApiDetailUrl); Assert.Equal(model.Object.PrimaryImageFile?.SiteDetailUrl, searchModel.PrimaryImageFileSiteDetailUrl); Assert.Equal(model.Object.PrimaryImageFile?.Name, searchModel.PrimaryImageFileName); Assert.Equal(model.Object.PrimaryImageFile?.ShortDescription, searchModel.PrimaryImageFileShortDescription); Assert.Equal(model.Object.PrimaryImageFile?.Description, searchModel.PrimaryImageFileDescription); Assert.Equal(model.Object.FirstIssueAppearanceId, searchModel.FirstIssueAppearanceId); Assert.Equal(model.Object.FirstIssueAppearance?.CustomKey, searchModel.FirstIssueAppearanceCustomKey); Assert.Equal(model.Object.FirstIssueAppearance?.ApiDetailUrl, searchModel.FirstIssueAppearanceApiDetailUrl); Assert.Equal(model.Object.FirstIssueAppearance?.SiteDetailUrl, searchModel.FirstIssueAppearanceSiteDetailUrl); Assert.Equal(model.Object.FirstIssueAppearance?.Name, searchModel.FirstIssueAppearanceName); Assert.Equal(model.Object.FirstIssueAppearance?.ShortDescription, searchModel.FirstIssueAppearanceShortDescription); Assert.Equal(model.Object.FirstIssueAppearance?.Description, searchModel.FirstIssueAppearanceDescription); Assert.Equal(model.Object.PublisherId, searchModel.PublisherId); Assert.Equal(model.Object.Publisher?.CustomKey, searchModel.PublisherCustomKey); Assert.Equal(model.Object.Publisher?.ApiDetailUrl, searchModel.PublisherApiDetailUrl); Assert.Equal(model.Object.Publisher?.SiteDetailUrl, searchModel.PublisherSiteDetailUrl); Assert.Equal(model.Object.Publisher?.Name, searchModel.PublisherName); Assert.Equal(model.Object.Publisher?.ShortDescription, searchModel.PublisherShortDescription); Assert.Equal(model.Object.Publisher?.Description, searchModel.PublisherDescription); }
public void UpdateWith(Team team) { TeamMapper mapper = new TeamMapper(); mapper.Update(team, this); }
public void TeamEntityModelTest() { var teamMapper = new TeamMapper(); var userMapper = new UserMapper(); Assert.Null(teamMapper.EntityToDetailModel(null)); Assert.Null(teamMapper.DetailModelToEntity(null)); var UserEntityObject = new UserEntity() { Id = 4, Name = "Anton", Password = "******", Email = "*****@*****.**", Comments = new Collection <CommentEntity>(), Posts = new Collection <PostEntity>() }; var TeamEntityObject = new TeamEntity() { Id = 2, Leader = UserEntityObject.Id, Name = "Team1" }; var UserModelObject = new UserDetailModel() { Id = 4, Name = "Anton", Password = "******", Email = "*****@*****.**", Comments = new Collection <CommentModel>(), Posts = new Collection <PostModel>() }; var TeamModelObject = new TeamDetailModel() { Id = 2, Leader = UserModelObject.Id, Members = new Collection <UserListModel>(), Name = "Team1" }; Assert.Equal(TeamModelObject, teamMapper.EntityToDetailModel(TeamEntityObject)); TeamEntityObject.Members = new Collection <TeamUserEntity>(); TeamModelObject.Members = null; Assert.Equal(TeamEntityObject, teamMapper.DetailModelToEntity(TeamModelObject)); TeamModelObject.Members = new Collection <UserListModel>(); TeamEntityObject.Members.Add(new TeamUserEntity() { UserId = UserEntityObject.Id, UserName = UserEntityObject.Name }); TeamModelObject.Members.Add(userMapper.DetailModelToListModel(UserModelObject)); Assert.Equal(TeamModelObject, teamMapper.EntityToDetailModel(TeamEntityObject)); Assert.Equal(TeamEntityObject, teamMapper.DetailModelToEntity(TeamModelObject)); }
//[ValidateAntiForgeryToken] ///<summary> /// Views all teams(admin, service manager and team leads) /// </summary> public ActionResult ViewAllTeams() { ActionResult oResponse = null; var viewAllTeamsVM = new TeamViewModel(); var userPO = (IUserPO)Session["UserModel"]; // Ensures authenticated if (userPO.Email != null && userPO.RoleID_FK >= (int)RoleEnum.Administrator && (int)RoleEnum.Team_Lead <= 3) { try { var allTeams = _TeamDataAccess.GetAllTeams(); var smAllTeams = _TeamDataAccess.GetAllSMTeamsByUserID(userPO.UserID); var smTeams = _TeamDataAccess.GetAllSMTeams(); var allUsers = _UserDataAccess.GetAllUsers(); var allAbsences = PointsDataAccess.ViewAllAbsences(); switch (userPO.RoleID_FK) { case 1: // TODO: Add widget data to view model/view // Maps from data objects to presentation objects. viewAllTeamsVM.ListOfPos = TeamMapper.MapListOfDOsToListOfPOs(allTeams); var bestStandingTeam = _TeamBusinessLogic.QueryBestStandingTeam(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences); var bottomStandingTeam = _TeamBusinessLogic.QueryWorstStandingTeam(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences); var teamRanker = _TeamBusinessLogic.QueryTeamRanker(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences); AssociateAdminValues(viewAllTeamsVM, bestStandingTeam, bottomStandingTeam, allAbsences, teamRanker, userPO); oResponse = View(viewAllTeamsVM); break; case 2: // TODO: Add Widget data to view model/view // Maps from data objects to presentation objects. viewAllTeamsVM.ListOfPos = TeamMapper.MapListOfDOsToListOfPOs(smAllTeams); //var teamAbsences = allAbsences.Where(a => a.); Need to retrieve absences by Team // TODO: list of service manager team absences viewAllTeamsVM.ListOfTeamAbsences = AbsenceMapper.MapListOfDOsToListOfPOs(allAbsences); var topEmployee = _TeamBusinessLogic.QueryBestStandingTeamMember(smTeams, allAbsences, allUsers, userPO.RoleID_FK); oResponse = View(viewAllTeamsVM); break; case 3: // TODO: Finish DA call for Team Lead lolololol var getAllTeams = _TeamDataAccess.GetAllTeamsByUserID(userPO.UserID); viewAllTeamsVM.ListOfPos = TeamMapper.MapListOfDOsToListOfPOs(getAllTeams); var topTeamMember = _TeamBusinessLogic.QueryBestStandingTeamMember(smTeams, allAbsences, allUsers, userPO.RoleID_FK); oResponse = View(viewAllTeamsVM); break; default: oResponse = View("Index", "Home"); break; } } catch (Exception ex) { ErrorLogger.LogError(ex, "ViewAllTeams", "Maint"); viewAllTeamsVM.ErrorMessage = "There was an issure retrieving the view all teams. Please try again. If the problem persists contact your IT department."; } } else { oResponse = RedirectToAction("Index", "Home"); } return(oResponse); }
public async Task <ActionResult <TeamDto> > GetById(int id) => TeamMapper.MapToDto( await _unitOfWork.TeamRepository .GetByIdAsync(id));