示例#1
0
        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));
        }
示例#2
0
        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);
        }
示例#3
0
        public Dto.Country Map(Dbo.Country country)
        {
            if (country == null)
            {
                return(null);
            }

            return(new Dto.Country
            {
                Id = country.CountryId,
                Name = country.Name
            });
        }
示例#4
0
        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));
        }