public async Task <Dto.Team> Update(Dto.Team team) { Validated.NotNull(team, nameof(team)); Dbo.City city = await this.cityService.GetByName(team.City.Name); if (city == null) { city = await this.cityService.Create(team.City); } team.City.Id = city.CityId; Dbo.Country country = await this.countryService.GetByName(team.Country.Name); if (country == null) { country = await this.countryService.Create(team.Country); } team.Country.Id = country.CountryId; Dbo.Team updatedTeam = this.unitOfWork.Teams.Update(mapper.Map(team)); await this.unitOfWork.SaveChanges(); return(mapper.Map(updatedTeam)); }
public async Task <Dbo.Country> Create(Dto.Country country) { Validated.NotNull(country, nameof(country)); Dbo.Country addedCountry = this.unitOfWork.Countries.Add(mapper.Map(country)); await this.unitOfWork.SaveChanges(); return(addedCountry); }
public Dto.Country Map(Dbo.Country country) { if (country == null) { return(null); } return(new Dto.Country { Id = country.CountryId, Name = country.Name }); }
public async Task <Dto.Team> Create(Dto.Team team) { Validated.NotNull(team, nameof(team)); Dbo.City city = await this.cityService.GetByName(team.City.Name); if (city == null) { city = await this.cityService.Create(team.City); } team.City.Id = city.CityId; Dbo.Country country = await this.countryService.GetByName(team.Country.Name); if (country == null) { country = await this.countryService.Create(team.Country); } // fill in competition ids where existing to avoid duplication of competitions team.Competitions = (await Task.WhenAll(team.Competitions.Select(async(competition) => { var existing = await this.competitionsService.GetByName(competition.Name); competition.Id = existing != null ? existing.CompetitionId : 0; return(competition); }))).ToArray(); team.Country.Id = country.CountryId; Dbo.Team addedTeam = this.unitOfWork.Teams.Add(mapper.Map(team)); await this.unitOfWork.SaveChanges(); return(mapper.Map(addedTeam)); }