Exemplo n.º 1
0
        public async Task PostNewBuilding(BuildingViewModel buildingViewModel)
        {
            using CampFinderDbContext context = dbContextFactory.CreateDbContext();
            await context.Buildings.AddAsync(mapper.Map <Building>(buildingViewModel));

            await context.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task PostNewTerrain(TerrainViewModel terrainViewModel)
        {
            using CampFinderDbContext context = dbContextFactory.CreateDbContext();
            await context.Terrains.AddAsync(mapper.Map <Terrain>(terrainViewModel));

            await context.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public IEnumerable <TerrainOverviewItemViewModel> GetTerrainsForSearch(TerrainSearchViewModel terrainSearch)
        {
            using CampFinderDbContext context = dbContextFactory.CreateDbContext();
            IQueryable <Terrain> terrains = context.Terrains
                                            .Include(t => t.Reviews)
                                            .Include(t => t.Place);

            if (terrainSearch != null)
            {
                terrains = GetSearch(terrains, terrainSearch);

                if (terrainSearch.Toilets)
                {
                    terrains = terrains.Where(t => t.Toilets);
                }
                if (terrainSearch.Water)
                {
                    terrains = terrains.Where(t => t.Water);
                }
                if (terrainSearch.Electricity)
                {
                    terrains = terrains.Where(t => t.Electricity);
                }
            }
            return(terrains.Select(t => mapper.Map <TerrainOverviewItemViewModel>(t)).ToList());
        }
Exemplo n.º 4
0
        public async Task <CampPlaceViewModel> GetCampPlace(Guid id)
        {
            using CampFinderDbContext context = dbContextFactory.CreateDbContext();
            CampPlace campplace = await context.CampPlaces
                                  .FindAsync(id);

            return(mapper.Map <CampPlaceViewModel>(campplace));
        }
Exemplo n.º 5
0
 public async Task <TerrainViewModel> GetTerrainViewModel(Guid id)
 {
     using CampFinderDbContext context = dbContextFactory.CreateDbContext();
     return(mapper.Map <TerrainViewModel>(await context.Terrains
                                          .Include(b => b.Person)
                                          .Include(b => b.Reviews)
                                          .Include(b => b.Place)
                                          .SingleAsync(t => t.Id.Equals(id))));
 }
Exemplo n.º 6
0
        public async Task <ReviewViewModel> PostNewReview(ReviewViewModel reviewViewModel)
        {
            Review review = mapper.Map <Review>(reviewViewModel);

            using CampFinderDbContext context = dbContextFactory.CreateDbContext();
            review = (await context.Reviews.AddAsync(review)).Entity;
            await context.SaveChangesAsync();

            return(mapper.Map <ReviewViewModel>(review));
        }
Exemplo n.º 7
0
        public async Task <BuildingViewModel> GetBuildingViewModel(Guid id)
        {
            using CampFinderDbContext context = dbContextFactory.CreateDbContext();
            Building building = await context.Buildings
                                .Include(b => b.Person)
                                .Include(b => b.Reviews)
                                .Include(b => b.Place)
                                .SingleAsync(b => b.Id.Equals(id));

            return(mapper.Map <BuildingViewModel>(building));
        }
Exemplo n.º 8
0
        public async Task <string> Delete <T>(Guid id) where T : CampPlace, new()
        {
            using CampFinderDbContext context = dbContextFactory.CreateDbContext();
            T campplace = await context.Set <T>()
                          .Include(c => c.Person)
                          .Include(c => c.Place)
                          .Include(c => c.Reviews)
                          .SingleAsync(c => c.Id == id);

            context.Remove(campplace);

            //await repository.Delete(campPlace);
            //await repository.DeletePerson(campPlace.Person);
            //await repository.DeletePlace(campPlace.Place);
            //await reviewRepository.Delete(campPlace.Reviews);


            return($"{campplace.Name} has been deleted");
        }
Exemplo n.º 9
0
        public IEnumerable <BuildingOverviewItemViewModel> GetBuildingSearch(BuildingSearchViewModel buildingSearch)
        {
            using CampFinderDbContext context = dbContextFactory.CreateDbContext();
            IQueryable <Building> buildings = context.Buildings
                                              .Include(t => t.Reviews)
                                              .Include(t => t.Place);

            if (buildingSearch != null)
            {
                buildings = GetSearch(buildings, buildingSearch);
                if (buildingSearch.Beds)
                {
                    buildings = buildings.Where(b => b.Beds);
                }
                if (buildingSearch.KitchenGear)
                {
                    buildings = buildings.Where(b => b.KitchenGear);
                }
            }
            return(buildings.Select(b => mapper.Map <BuildingOverviewItemViewModel>(b)).ToList());
        }
Exemplo n.º 10
0
 public CampSiteRepository(CampFinderDbContext campFinderDbContext, ILogger <CampSiteRepository> logger)
 {
     _campFinderDbContext = campFinderDbContext;
     this.logger          = logger;
 }
Exemplo n.º 11
0
 public CategoryRepository(CampFinderDbContext campFinderDbContext)
 {
     _campFinderDbContext = campFinderDbContext;
 }
Exemplo n.º 12
0
 public IEnumerable <ReviewViewModel> GetReviewsById(Guid id)
 {
     using CampFinderDbContext context = dbContextFactory.CreateDbContext();
     return(context.Reviews.Where(r => r.CampPlaceId.Equals(id)).Select(r => mapper.Map <ReviewViewModel>(r)).ToList());
 }