public async Task <ActionResult <IEnumerable <GenreDTO> > > GetGenres()
        {
            var genres = await genreRepo.GetAllAsync();

            var genresDTO = mapper.Map <IEnumerable <GenreDTO> >(genres);

            return(Ok(genresDTO));
        }
Esempio n. 2
0
        public virtual async Task <IActionResult> GetAll()
        {
            try {
                var objList = await _repo.GetAllAsync();

                var resoureList = _mapper.Map <IEnumerable <TEntityResource> >(objList);

                return(Ok(resoureList));
            } catch (Exception ex) {
                _logger.LogError(ex.Message);
                return(BadRequest());
            }
        }
        public async Task <ActionResult <IEnumerable <PriceClassDTO> > > GetPrices()
        {
            IEnumerable <PriceClass> prices;

            try
            {
                prices = await genericPriceRepo.GetAllAsync();

                IEnumerable <PriceClassDTO> priceClassDTOs = mapper.Map <IEnumerable <PriceClass>, IEnumerable <PriceClassDTO> >(prices);
                return(Ok(priceClassDTOs));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("HandleErrorCode", "Error", new
                {
                    statusCode = 400,
                    errorMessage = $"Failed to get prices : {ex}"
                }));
            }
        }
        public async Task <ActionResult <IEnumerable <CategoryDTO> > > GetCategories()
        {
            IEnumerable <Category> categoriesCached;

            // if cache ? aanmaken of gebruiken
            if (!memoryCache.TryGetValue(CacheKeys.CategoriesCacheKey, out categoriesCached))
            {
                categoriesCached = await genericRepo.GetAllAsync();

                //relaties -> recipes
                foreach (Category c in categoriesCached)
                {
                    var recipes = await genericRecipeRepo.GetByExpressionAsync(r => r.CategoryId == c.Id);

                    c.Recipes = (ICollection <Recipe>)recipes;
                }

                //2. Set options
                var cacheEntryOptions = new MemoryCacheEntryOptions()
                                        .SetSize(10)
                                        .SetSlidingExpiration(TimeSpan.FromMinutes(1));

                //3. Save data in cache
                memoryCache.Set(CacheKeys.CategoriesCacheKey, categoriesCached, cacheEntryOptions);
            }
            else
            {
                categoriesCached = (ICollection <Category>)memoryCache.Get(CacheKeys.CategoriesCacheKey);
            }

            //3. mappen naar DTO
            var categoriesDTO = mapper.Map <IEnumerable <CategoryDTO> >(categoriesCached);

            //4. Notificatie met geserialiseerde categoriesDTO naar een Hub sturen (registreren)
            await hubContext.Clients.All.SendAsync("ServerMessage", new { message = $"{JsonSerializer.Serialize(categoriesDTO)}" });

            //alternatief: methode in RepoHub oproepen

            return(Ok(categoriesDTO));
        }
Esempio n. 5
0
        public async Task <List <VaccinationCenter> > GetVaccinationCentersAsync()
        {
            List <VaccinationCenter> resultList = await _repo.GetAllAsync();

            return(resultList);
        }
Esempio n. 6
0
 public async Task <ActionResult <List <ProductType> > > GetProductTypes() => Ok(await _productTypeRepo.GetAllAsync());
Esempio n. 7
0
 public async Task <ActionResult <List <ProductBrand> > > GetProductBrands() => Ok(await _productBrandRepo.GetAllAsync());