private IList <RaceDto> MakeRaces(SwObjects.Series series) { var retList = new List <RaceDto>(); foreach (var swRace in series.Races) { DateTime date = GetDate(swRace, _season); int rank = GetRaceRank(swRace); var ssRace = new RaceDto { Name = swRace.Name, Order = rank, ClubId = _club.Id, Date = date, FleetId = _fleet.Id, SeriesIds = new List <Guid> { _series.Id } }; ssRace.Scores = MakeScores(swRace, series.Competitors, _boatClass, _fleet); retList.Add(ssRace); } return(retList); }
public async Task <ActionResult <Guid> > Post([FromBody] RaceDto race) { if (!await _authService.CanUserEdit(User, race.ClubId)) { return(Unauthorized()); } return(Ok(await _service.SaveAsync(race))); }
public async Task <ActionResult> Remove([FromBody] RaceDto race) { Race dbRace = this.mapper.Map <Race>(race); return((await this.raceLogic.RemoveAsync(dbRace)) ? this.StatusCode(200) : this.StatusCode(400)); }
internal Race ToPoco(RaceDto r) { return(new Race { Id = r.Id, Name = r.Name, StarTime = new DateTime(r.StartTime) }); }
public Task<Guid> SaveAsync(RaceDto race) { if (race == null) { throw new ArgumentNullException(nameof(race)); } return SaveInternalAsync(race); }
public async Task <ActionResult> SaveRace([FromBody] RaceDto race) { Race dbRace = this.mapper.Map <Race>(race); var result = await this.raceLogic.SaveAsync(dbRace); return(result.Match( success => this.StatusCode(200, success.Id), validationError => this.StatusCode(400, validationError.Errors), error => this.StatusCode(500, error.ErrorCode))); }
public RaceBase Build(RaceDto race) { if (race.Gender == (int)EArtificialLifeGender.ROBOT) { return(new Robot(race.Id, race.FirstName, race.LastName)); } else { return(new Artificial(race.Id, race.FirstName, race.Gender)); } }
protected RaceBase Build(RaceDto race) { Dictionary <string, IRaceFactory> strategy = new Dictionary <string, IRaceFactory> { { RaceClassificators.HUMAN, new HumanFactory() }, { RaceClassificators.KREE, new KreeFactory() }, { RaceClassificators.ARTIFICIAL, new ArtificialLifeFactory() }, }; var character = strategy[race.RaceDiscriminator].Build(race); return(character); }
public IEnumerable <RaceDto> GetAllRaces(int tournamentId) { ITournament tournament = TournamentManager.GetTournament(tournamentId); List <RaceDto> result = new List <RaceDto>(); foreach (IRace race in tournament.Races) { result.Add(RaceDto.FromRace(race)); } return(result); }
private void PopulateWeather(RaceDto race, Db.Race dbRace) { if (dbRace.Weather == null) { var dbObj = _mapper.Map<Database.Entities.Weather>(race.Weather); dbRace.Weather = dbObj; } else { var id = dbRace.Weather.Id; var createdDate = dbRace.Weather.CreatedDate; _mapper.Map<WeatherDto, Database.Entities.Weather>(race.Weather, dbRace.Weather); dbRace.Weather.CreatedDate = createdDate; dbRace.Weather.Id = id; } }
public async Task Save_NewNoSeries_IncreasesCount() { var racesBefore = await _service.GetRacesAsync( _clubId ); var dto = new RaceDto { ClubId = _clubId, Date = DateTime.Today, Order = 1 }; await _service.SaveAsync(dto); var racesAfter = await _service.GetRacesAsync( _clubId ); Assert.Equal(racesBefore.Count() + 1, racesAfter.Count()); }
public async Task <Guid> SaveRace(RaceDto race) { return(await PostAsync <RaceDto>($"/api/races/", race)); }
public RaceBase Build(RaceDto race) { return(new Human(race.Id, race.FirstName, race.LastName, race.Gender)); }
private async Task<Guid> SaveInternalAsync(RaceDto race) { var dbRace = new Db.Race { Id = Guid.NewGuid(), ClubId = race.ClubId }; if (race.Id != default) { dbRace = await _dbContext.Races .Include(r => r.Scores) .Include(r => r.SeriesRaces) .Include(r => r.Weather) .AsSingleQuery() .SingleAsync(r => r.Id == race.Id) .ConfigureAwait(false); } IEnumerable<Guid> seriesIdsToUpdate = dbRace.SeriesRaces?.Select(r => r.SeriesId)?.ToList() ?? new List<Guid>(); dbRace.Name = race.Name; dbRace.Order = race.Order; dbRace.Date = race.Date ?? DateTime.Today; dbRace.Description = race.Description; dbRace.State = race.State; dbRace.TrackingUrl = race.TrackingUrl; dbRace.UpdatedDate = DateTime.UtcNow; dbRace.UpdatedBy = race.UpdatedBy; PopulateWeather(race, dbRace); dbRace.Fleet = _dbContext.Fleets.SingleOrDefault(f => f.Id == race.FleetId); if (race.SeriesIds != null) { dbRace.SeriesRaces ??= new List<Db.SeriesRace>(); dbRace.SeriesRaces.Clear(); foreach (var seriesId in race.SeriesIds) { dbRace.SeriesRaces.Add(new Db.SeriesRace { SeriesId = seriesId, RaceId = dbRace.Id }); } } if (race.Scores != null) { dbRace.Scores ??= new List<Db.Score>(); dbRace.Scores.Clear(); foreach (var score in race.Scores) { var newScore = new Db.Score { Id = Guid.NewGuid(), CompetitorId = score.CompetitorId, Race = dbRace, Place = score.Place, Code = score.Code, CodePoints = score.CodePoints }; _dbContext.Scores.Add(newScore); } } if (race.Id == default) { _dbContext.Races.Add(dbRace); } else { _dbContext.Races.Update(dbRace); } await _dbContext.SaveChangesAsync() .ConfigureAwait(false); seriesIdsToUpdate = seriesIdsToUpdate.Union( dbRace.SeriesRaces?.Select(rs => rs.SeriesId).ToList() ?? new List<Guid>()); foreach (var seriesId in seriesIdsToUpdate) { AddUpdateSeriesJob(seriesId, race.UpdatedBy); } return dbRace.Id; }
RaceDto(RaceDto data) { name = data.name; icon = data.icon; }