public T Delete(T entity) { Validated.NotNull(entity, nameof(entity)); var entry = this.context.Entry(entity); return(this.context.Set <T>().Remove(entity).Entity); }
public WebsiteService(IUnitOfWork unitOfWork, ICategoryService categoryService) { Validated.NotNull(unitOfWork, nameof(unitOfWork)); Validated.NotNull(categoryService, nameof(categoryService)); this.unitOfWork = unitOfWork; this.categoryService = categoryService; }
public T Update(T entity) { Validated.NotNull(entity, nameof(entity)); EntityEntry entry = this.context.Entry(entity); return(this.context.Set <T>().Update(entity).Entity); }
public CountryService(IUnitOfWork unitOfWork, IMapper mapper) { Validated.NotNull(unitOfWork, nameof(unitOfWork)); Validated.NotNull(mapper, nameof(mapper)); this.unitOfWork = unitOfWork; this.mapper = mapper; }
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 GameProcessor(IRandomProvider random, ICardsRepository cardsRepository) { Validated.NotNull(random, nameof(random)); Validated.NotNull(cardsRepository, nameof(cardsRepository)); this.random = random; this.cardsRepository = cardsRepository; }
public GameController(IBalanceRepository balanceRepository, IGameProcessor gameProcessor) { Validated.NotNull(balanceRepository, nameof(balanceRepository)); Validated.NotNull(gameProcessor, nameof(gameProcessor)); this.balanceRepository = balanceRepository; this.gameProcessor = gameProcessor; }
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 async Task <SportEvent> Update(SportEvent sportEvent) { Validated.NotNull(sportEvent, nameof(sportEvent)); SportEvent updatedSportEvent = this.unitOfWork.SportEvents.Update(sportEvent); await this.unitOfWork.SaveChanges(); return(updatedSportEvent); }
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); }
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); }
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()); }
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; }
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)); }
public EFRepository(MsSqlDbContext context) { Validated.NotNull(context, nameof(context)); this.context = context; }
public WebSiteController(IWebsiteService websiteService) { Validated.NotNull(websiteService, nameof(websiteService)); this.websiteService = websiteService; }
public CategoryService(IUnitOfWork unitOfWork) { Validated.NotNull(unitOfWork, nameof(unitOfWork)); this.unitOfWork = unitOfWork; }