Ejemplo 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));
        }
Ejemplo n.º 2
0
        private Dto.Team ShortMap(Dbo.Team team)
        {
            if (team == null)
            {
                return(null);
            }

            var result = new Dto.Team
            {
                Id   = team.TeamId,
                Name = team.Name,
            };

            return(result);
        }
Ejemplo n.º 3
0
        public Dto.Team Map(Dbo.Team team)
        {
            if (team == null)
            {
                return(null);
            }

            var result = new Dto.Team
            {
                Id           = team.TeamId,
                Name         = team.Name,
                City         = Map(team.City),
                Country      = Map(team.Country),
                Competitions = team.Competitions.Select(c => Map(c.Competition)).ToArray()
            };

            return(result);
        }
Ejemplo n.º 4
0
        public Dbo.Team Map(Dto.Team team)
        {
            if (team == null)
            {
                return(null);
            }

            var result = new Dbo.Team
            {
                TeamId       = team.Id,
                Name         = team.Name,
                CityId       = team.City.Id,
                CountryId    = team.Country.Id,
                Competitions = team.Competitions.Select(competition => Map(competition, team.Id)).ToList()
            };

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