Esempio n. 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));
        }
Esempio n. 2
0
        public async Task <Dbo.City> Create(Dto.City city)
        {
            Validated.NotNull(city, nameof(city));

            Dbo.City addedCity = this.unitOfWork.Cities.Add(mapper.Map(city));

            await this.unitOfWork.SaveChanges();

            return(addedCity);
        }
Esempio n. 3
0
        public Dto.City Map(Dbo.City city)
        {
            if (city == null)
            {
                return(null);
            }

            var result = new Dto.City
            {
                Id   = city.CityId,
                Name = city.Name
            };

            return(result);
        }
Esempio n. 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));
        }