示例#1
0
        public T Delete(T entity)
        {
            Validated.NotNull(entity, nameof(entity));
            var entry = this.context.Entry(entity);

            return(this.context.Set <T>().Remove(entity).Entity);
        }
示例#2
0
 public WebsiteService(IUnitOfWork unitOfWork, ICategoryService categoryService)
 {
     Validated.NotNull(unitOfWork, nameof(unitOfWork));
     Validated.NotNull(categoryService, nameof(categoryService));
     this.unitOfWork      = unitOfWork;
     this.categoryService = categoryService;
 }
示例#3
0
        public T Update(T entity)
        {
            Validated.NotNull(entity, nameof(entity));
            EntityEntry entry = this.context.Entry(entity);

            return(this.context.Set <T>().Update(entity).Entity);
        }
示例#4
0
 public CountryService(IUnitOfWork unitOfWork, IMapper mapper)
 {
     Validated.NotNull(unitOfWork, nameof(unitOfWork));
     Validated.NotNull(mapper, nameof(mapper));
     this.unitOfWork = unitOfWork;
     this.mapper     = mapper;
 }
示例#5
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));
        }
示例#6
0
        public GameProcessor(IRandomProvider random, ICardsRepository cardsRepository)
        {
            Validated.NotNull(random, nameof(random));
            Validated.NotNull(cardsRepository, nameof(cardsRepository));

            this.random          = random;
            this.cardsRepository = cardsRepository;
        }
示例#7
0
        public GameController(IBalanceRepository balanceRepository, IGameProcessor gameProcessor)
        {
            Validated.NotNull(balanceRepository, nameof(balanceRepository));
            Validated.NotNull(gameProcessor, nameof(gameProcessor));

            this.balanceRepository = balanceRepository;
            this.gameProcessor     = gameProcessor;
        }
示例#8
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);
        }
示例#9
0
        public async Task <SportEvent> Update(SportEvent sportEvent)
        {
            Validated.NotNull(sportEvent, nameof(sportEvent));

            SportEvent updatedSportEvent = this.unitOfWork.SportEvents.Update(sportEvent);

            await this.unitOfWork.SaveChanges();

            return(updatedSportEvent);
        }
示例#10
0
        public async Task <Dbo.Competition> Create(Dto.Competition competition)
        {
            Validated.NotNull(competition, nameof(competition));

            Dbo.Competition addedCompetition = this.unitOfWork.Competitions.Add(mapper.Map(competition));

            await this.unitOfWork.SaveChanges();

            return(addedCompetition);
        }
示例#11
0
        public async Task <Category> Update(Category category)
        {
            Validated.NotNull(category, nameof(category));

            Category updatedCategory = this.unitOfWork.Categories.Update(category);

            await this.unitOfWork.SaveChanges();

            return(updatedCategory);
        }
示例#12
0
        public async Task <Dto.WebSite> Create(Dto.WebSite website)
        {
            Validated.NotNull(website, nameof(website));

            Dbo.Category category = await this.categoryService.GetByName(website.Category.Name);

            if (category == null)
            {
                category = await this.categoryService.Create(website.Category.Map());
            }

            website.Category.Id = category.Id;

            Dbo.WebSite addedWebsite = this.unitOfWork.WebSites.Add(website.Map());

            await this.unitOfWork.SaveChanges();

            return(addedWebsite.Map());
        }
示例#13
0
 public UnitOfWork(
     MsSqlDbContext context,
     IEfRepository <City> cities,
     IEfRepository <Competition> competitions,
     IEfRepository <Country> countries,
     IEfRepository <Game> games,
     IEfRepository <Team> teams
     )
 {
     Validated.NotNull(context, nameof(context));
     Validated.NotNull(cities, nameof(cities));
     Validated.NotNull(competitions, nameof(competitions));
     Validated.NotNull(countries, nameof(countries));
     Validated.NotNull(games, nameof(games));
     Validated.NotNull(teams, nameof(teams));
     this.context      = context;
     this.cities       = cities;
     this.competitions = competitions;
     this.countries    = countries;
     this.games        = games;
     this.teams        = teams;
 }
示例#14
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));
        }
示例#15
0
 public EFRepository(MsSqlDbContext context)
 {
     Validated.NotNull(context, nameof(context));
     this.context = context;
 }
示例#16
0
 public WebSiteController(IWebsiteService websiteService)
 {
     Validated.NotNull(websiteService, nameof(websiteService));
     this.websiteService = websiteService;
 }
示例#17
0
 public CategoryService(IUnitOfWork unitOfWork)
 {
     Validated.NotNull(unitOfWork, nameof(unitOfWork));
     this.unitOfWork = unitOfWork;
 }