public ServiceMessage Delete(string sportName) { string message; bool success = true; try { SportEntity sportEntity = unitOfWork.Sports.Get(sportName); if (sportEntity != null) { unitOfWork.Sports.Remove(sportEntity); unitOfWork.Commit(); message = "Sport deleted"; } else { message = "Sport with such name doesn't exist"; success = false; } } catch (Exception ex) { message = ExceptionMessageBuilder.BuildMessage(ex); success = false; } return(new ServiceMessage(message, success)); }
public async Task <IActionResult> Create(SportViewModel sportViewModel) { if (ModelState.IsValid) { string path = string.Empty; if (sportViewModel.LogoFile != null) { path = await _imageHelper.UploadImageAsync(sportViewModel.LogoFile, "Sports"); } SportEntity sportEntity = _converterHelper.ToSportEntity(sportViewModel, path, true); _context.Add(sportEntity); try { await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, $"Already exists the sport: {sportEntity.Name}"); } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); } } } return(View(sportViewModel)); }
public ServiceMessage Update(SportEditDTO sportEditDTO) { string message; bool success = true; try { SportEntity sportEntity = unitOfWork .Sports .Get(sportEditDTO.OldSportName); if (sportEntity != null) { sportEntity.Type = sportEditDTO.NewSportName; unitOfWork.Commit(); message = "Sport was renamed"; } else { message = "Sport with such name doesn't exist"; success = false; } } catch (Exception ex) { message = ExceptionMessageBuilder.BuildMessage(ex); success = false; } return(new ServiceMessage(message, success)); }
public void Delete(SportEntity entity) { using (var uow = unitOfWorkFactory.CreateUnitOfWork()) { uow.SportRepository.Delete(entity); uow.Save(); } }
public SportViewModel ToSportViewModel(SportEntity sportEntity) { return(new SportViewModel { Id = sportEntity.Id, LogoPath = sportEntity.LogoPath, Name = sportEntity.Name }); }
public TeamEntity ToEntity(Team team) { SportEntity convertedSport = sportConverter.ToEntity(team.Sport); TeamEntity convertedTeam = new TeamEntity(team.Id, team.Name, team.PhotoPath, convertedSport.Name, convertedSport); convertedTeam.Sport = convertedSport; convertedTeam.SportEntityName = team.Sport.Name; return(convertedTeam); }
public void SetUp() { testMapper = new SportMapper(); sport = new Mock <Sport>("Soccer", true); entity = new SportEntity() { Name = "Soccer", }; }
public Sport Get(string name) { if (!Exists(name)) { throw new SportNotFoundException(); } SportEntity sportInDb = context.Sports.First(s => s.Name == name); return(mapper.ToSport(sportInDb)); }
public SportEntity ToEntity(Sport aSport) { SportEntity converted = new SportEntity() { Name = aSport.Name, IsTwoTeams = aSport.IsTwoTeams }; return(converted); }
public void TestInitialize() { mockTeam = new Mock <Team>(1, "DreamTeam", "/MyResource/DreamTeam.png"); SportEntity sport = new SportEntity() { Name = "aSport", IsTwoTeams = false }; mockTeamEntity = new TeamEntity(1, "DreamTeam", "/MyResource/DreamTeam.png", "aSport", sport); teamMapper = new TeamMapper(); }
public void Modify(Sport entity) { if (!Exists(entity.Name)) { throw new SportNotFoundException(); } SportEntity modified = mapper.ToEntity(entity); context.Entry(modified).State = EntityState.Modified; context.SaveChanges(); }
public void Delete(string name) { if (!Exists(name)) { throw new SportNotFoundException(); } SportEntity sportInDb = context.Sports.First(s => s.Name == name); context.Sports.Remove(sportInDb); DeleteTeamsMatches(name); context.SaveChanges(); }
public ServiceMessage Create(TournamentBaseDTO tournamentCreateDTO) { string message = ""; bool success = true; if (success = Validate(tournamentCreateDTO, ref message)) { string name = tournamentCreateDTO.Name; string sportName = tournamentCreateDTO.SportName; DateTime dateOfStart = tournamentCreateDTO.DateOfStart; try { SportEntity sportEntity = unitOfWork.Sports.Get(sportName); if (sportEntity != null) { bool exists = unitOfWork.Tournaments.Exists(name, sportEntity.Id, dateOfStart); if (!exists) { TournamentEntity tournamentEntity = new TournamentEntity { Name = name, DateOfStart = dateOfStart, SportId = sportEntity.Id }; unitOfWork.Tournaments.Add(tournamentEntity); unitOfWork.Commit(); message = "Created new tournament"; } else { message = "Such tournament already exists"; success = false; } } else { message = "No such sport found"; success = false; } } catch (Exception ex) { message = ExceptionMessageBuilder.BuildMessage(ex); success = false; } } return(new ServiceMessage(message, success)); }
public SportResponse ToSportResponse(SportEntity sportEntity) { return(new SportResponse { Id = sportEntity.Id, Name = sportEntity.Name, LogoPath = sportEntity.LogoPath, Tournaments = sportEntity.Tournaments?.Select(t => new TournamentResponse { EndDate = t.EndDate, Id = t.Id, IsActive = t.IsActive, LogoPath = t.LogoPath, Name = t.Name, StartDate = t.StartDate, Groups = t.Groups?.Select(g => new GroupResponse { Id = g.Id, Name = g.Name, GroupDetails = g.GroupDetails?.Select(gd => new GroupDetailResponse { GoalsAgainst = gd.GoalsAgainst, GoalsFor = gd.GoalsFor, Id = gd.Id, MatchesLost = gd.MatchesLost, MatchesPlayed = gd.MatchesPlayed, MatchesTied = gd.MatchesTied, MatchesWon = gd.MatchesWon, Team = ToTeamResponse(gd.Team) }).ToList(), Matches = g.Matches?.Select(m => new MatchResponse { Date = m.Date, GoalsLocal = m.GoalsLocal, GoalsVisitor = m.GoalsVisitor, Id = m.Id, IsClosed = m.IsClosed, Local = ToTeamResponse(m.Local), Visitor = ToTeamResponse(m.Visitor), Predictions = m.Predictions?.Select(p => new PredictionResponse { GoalsLocal = p.GoalsLocal, GoalsVisitor = p.GoalsVisitor, Id = p.Id, Points = p.Points, User = ToUserResponse(p.User) }).ToList() }).ToList() }).ToList() }).ToList() }); }
public Sport Add(Sport sport) { if (Exists(sport.Name)) { throw new SportAlreadyExistsException(); } SportEntity entity = mapper.ToEntity(sport); context.Entry(entity).State = EntityState.Added; context.SaveChanges(); return(mapper.ToSport(entity)); }
//TODO //Create and Update have much same code public ServiceMessage Create(ParticipantBaseDTO participantBaseDTO) { string message; bool success = true; string sportName = participantBaseDTO.SportName; string countryName = participantBaseDTO.CountryName; string participantName = participantBaseDTO.Name; try { SportEntity sportEntity = unitOfWork.Sports.Get(sportName); CountryEntity countryEntity = unitOfWork.Countries.Get(countryName); if (sportEntity != null && countryEntity != null) { bool exists = unitOfWork.Participants.Exists(participantName, sportEntity.Id, countryEntity.Id); if (!exists) { ParticipantEntity participantEntity = new ParticipantEntity { Name = participantName, CountryId = countryEntity.Id, SportId = sportEntity.Id }; unitOfWork.Participants.Add(participantEntity); unitOfWork.Commit(); message = "Created new participant"; } else { message = "Such participant already exists"; success = false; } } else { message = "Such sport or country was not found"; success = false; } } catch (Exception ex) { message = ExceptionMessageBuilder.BuildMessage(ex); success = false; } return(new ServiceMessage(message, success)); }
public EncounterEntity ToEntity(Encounter anEncounter) { SportEntity sportEntity = sportConverter.ToEntity(anEncounter.Sport); EncounterEntity conversion = new EncounterEntity() { Id = anEncounter.Id, Date = anEncounter.Date, Commentaries = TransformCommentaries(anEncounter.GetAllCommentaries()), SportEntity = sportEntity, HasResult = anEncounter.HasResult() }; return(conversion); }
public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } SportEntity sportEntity = await _context.Sports .FirstOrDefaultAsync(m => m.Id == id); if (sportEntity == null) { return(NotFound()); } return(View(sportEntity)); }
public void SetUp() { factory = new EncounterFactory(); testMapper = new EncounterMapper(); SportEntity testSport = new SportEntity() { Name = "Soccer", IsTwoTeams = true }; TeamEntity homeTest = new TeamEntity { TeamNumber = 3, SportEntityName = "Soccer", Sport = testSport, Name = "Nacional", Photo = "aPath" }; TeamEntity awayTest = new TeamEntity { TeamNumber = 4, SportEntityName = "Soccer", Sport = testSport, Name = "Torque", Photo = "aPath" }; entity = new EncounterEntity() { Id = 3, Date = DateTime.Now, SportEntity = testSport, HasResult = false, Commentaries = new List <CommentEntity>() }; EncounterTeam homeRel = new EncounterTeam() { Team = homeTest, TeamNumber = 3, Encounter = entity, EncounterId = 3 }; EncounterTeam awayRel = new EncounterTeam() { Team = awayTest, TeamNumber = 4, Encounter = entity, EncounterId = 3 }; playingTeams = new List <EncounterTeam>() { homeRel, awayRel }; homeMock = new Team(3, "Nacional", "aPath", new Sport("Soccer", true)); awayMock = new Team(4, "Torque", "aPath", new Sport("Soccer", true)); Sport sport = new Sport("Soccer", true); match = factory.CreateEncounter(new List <Team>() { homeMock, awayMock }, DateTime.Now, sport); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } SportEntity sportEntity = await _context.Sports.FindAsync(id); if (sportEntity == null) { return(NotFound()); } SportViewModel sportViewModel = _converterHelper.ToSportViewModel(sportEntity); return(View(sportViewModel)); }
public ServiceMessage Delete(ParticipantBaseDTO participantBaseDTO) { string message; bool success = true; string sportName = participantBaseDTO.SportName; string countryName = participantBaseDTO.CountryName; string participantName = participantBaseDTO.Name; try { SportEntity sportEntity = unitOfWork.Sports.Get(sportName); CountryEntity countryEntity = unitOfWork.Countries.Get(countryName); if (sportEntity != null && countryEntity != null) { ParticipantEntity participantEntity = unitOfWork.Participants.Get(participantName, sportEntity.Id, countryEntity.Id); if (participantEntity != null) { unitOfWork.Participants.Remove(participantEntity); unitOfWork.Commit(); message = "Deleted participant"; } else { message = "Such participant doesn't exist"; success = false; } } else { message = "Such sport or country was not found"; success = false; } } catch (Exception ex) { message = ExceptionMessageBuilder.BuildMessage(ex); success = false; } return(new ServiceMessage(message, success)); }
// GET: Sports/Delete/5 public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } SportEntity sportEntity = await _context.Sports.FirstOrDefaultAsync(m => m.Id == id); if (sportEntity == null) { return(NotFound()); } _context.Sports.Remove(sportEntity); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public DataServiceMessage <IEnumerable <ParticipantBaseDTO> > GetBySport(string sportName) { string message; bool success = true; IEnumerable <ParticipantBaseDTO> partipantDisplayDTOs = null; try { SportEntity sportEntity = unitOfWork.Sports.Get(sportName); if (sportEntity != null) { IEnumerable <ParticipantEntity> participantEntities = unitOfWork.Participants.GetAll(p => p.SportId == sportEntity.Id); partipantDisplayDTOs = participantEntities .Select(participant => { return(new ParticipantBaseDTO { Name = participant.Name, CountryName = participant.Country.Name, SportName = participant.Sport.Type }); }) .OrderBy(p => p.Name) .ToList(); message = "Got all participants"; } else { message = "No such sport found"; success = false; } } catch (Exception ex) { message = ExceptionMessageBuilder.BuildMessage(ex); success = false; } return(new DataServiceMessage <IEnumerable <ParticipantBaseDTO> >(partipantDisplayDTOs, message, success)); }
public ServiceMessage Delete(TournamentBaseDTO tournamentBaseDTO) { string message = ""; bool success = true; string name = tournamentBaseDTO.Name; string sportName = tournamentBaseDTO.SportName; DateTime dateOfStart = tournamentBaseDTO.DateOfStart; try { SportEntity sportEntity = unitOfWork.Sports.Get(sportName); if (sportEntity != null) { TournamentEntity tournamentEntity = unitOfWork.Tournaments.Get(name, sportEntity.Type, dateOfStart); if (tournamentEntity != null) { unitOfWork.Tournaments.Remove(tournamentEntity); unitOfWork.Commit(); message = "Deleted tournament"; } else { message = "Such tournament doesn't exist"; success = false; } } else { message = "No such sport found"; success = false; } } catch (Exception ex) { message = ExceptionMessageBuilder.BuildMessage(ex); success = false; } return(new ServiceMessage(message, success)); }
public async Task Save(SportEntity sport) { _context.Sports.Add(sport); await _context.SaveChangesAsync(); }
public void SportToEntityNameTest() { SportEntity converted = testMapper.ToEntity(sport.Object); Assert.AreEqual(converted.Name, entity.Name); }
public ServiceMessage UpdateParticipants(EventEditDTO eventEditDTO) { string message = ""; bool success = true; string sportName = eventEditDTO.SportName; string tournamentName = eventEditDTO.TournamentName; DateTime dateOfTournamentStart = eventEditDTO.DateOfTournamentStart; DateTime dateOfEvent = eventEditDTO.DateOfEvent; List <ParticipantBaseDTO> participants = eventEditDTO.Participants; List <ParticipantBaseDTO> newParticipants = eventEditDTO.NewParticipants; if (success = Validate(eventEditDTO, ref message)) { if (newParticipants != null && newParticipants.Count > 1) { try { TournamentEntity tournamentEntity = unitOfWork.Tournaments.Get(tournamentName, sportName, dateOfTournamentStart); if (tournamentEntity != null) { IEnumerable <ParticipantEntity> oldParticipantEntities = participants .Select(p => unitOfWork.Participants.Get(p.Name, p.SportName, p.CountryName)) .ToList(); EventEntity eventEntity = unitOfWork .Events .Get(sportName, tournamentName, dateOfEvent, oldParticipantEntities); if (eventEntity != null) { IEnumerable <ParticipantEntity> newParticipantEntities = newParticipants .Select(p => unitOfWork.Participants.Get(p.Name, p.SportName, p.CountryName)); bool sportValidated = true; SportEntity sportEntity = tournamentEntity.Sport; if (sportEntity.IsDual) { if (newParticipantEntities.Count() != 2) { message = "Sport is dual. Only 2 participants allowed"; success = false; sportValidated = false; } } if (sportValidated) { var added = newParticipantEntities.Except(oldParticipantEntities).ToList(); var deleted = oldParticipantEntities.Except(newParticipantEntities).ToList(); bool anyParticipantBusy = added .Any(p => unitOfWork.Participants.IsBusyOn(p.Id, dateOfEvent)); if (!anyParticipantBusy) { var deletedParticipations = eventEntity .Participations .Where(part => deleted.Select(p => p.Id).Contains(part.ParticipantId)) .ToList(); foreach (var participation in deletedParticipations) { eventEntity.Participations.Remove(participation); } foreach (var participant in added) { eventEntity.Participations.Add(new ParticipationEntity { EventId = eventEntity.Id, ParticipantId = participant.Id }); } unitOfWork.Commit(); message = "Changed participants of event"; } else { message = "One or more participant is busy this date"; success = false; } } } else { message = "Such event was not found"; success = false; } } else { message = "Such tournament was not found"; success = false; } } catch (Exception ex) { message = ExceptionMessageBuilder.BuildMessage(ex); success = false; } } else { message = "Invalid count of participants"; success = false; } } return(new ServiceMessage(message, success)); }
public void Update(SportEntity entity) { throw new System.NotImplementedException(); }
public void Update(Sport source, SportEntity destination) { destination.SportName = source.Name; destination.EncounterPlayerCount = source.EncounterPlayerCount; }
public Sport Map(SportEntity entity) { return(new Sport(name: entity.SportName, encounterPlayerCount: entity.EncounterPlayerCount)); }