Ejemplo n.º 1
0
        public async Task <CheeseEntity> CreateCheese(CheeseEntity newCheese, CancellationToken cancellationToken)
        {
            var result = await _dbContext.Cheeses.AddAsync(newCheese);

            await _dbContext.SaveChangesAsync();

            return(result.Entity);
        }
Ejemplo n.º 2
0
        public async Task <CheeseEntity> UpdateCheese(CheeseEntity updateCheese, CancellationToken cancellationToken)
        {
            var result = await _dbContext.Cheeses.FirstOrDefaultAsync(ch => ch.Id == updateCheese.Id);

            if (result != null)
            {
                result.CommonName = updateCheese.CommonName;
                result.Country    = updateCheese.Country;
                result.UpdatedAt  = DateTime.UtcNow;

                await _dbContext.SaveChangesAsync();

                return(result);
            }

            return(null);
        }
Ejemplo n.º 3
0
        public async Task <IEnumerable <GetCheeseResponse> > ProcessAsync(GetCheeseRequest request, CancellationToken cancellationToken)
        {
            if (request.Id > 0)
            {
                CheeseEntity reqEntity = await _cheeseRepository.GetCheese(request.Id, cancellationToken);

                var selectedCheese = _mapper.Map <GetCheeseResponse>(reqEntity);
                return(new List <GetCheeseResponse> {
                    selectedCheese
                });
            }
            else
            {
                var allCheeseEntity = await _cheeseRepository.GetCheeseCollection(cancellationToken);

                return(_mapper.Map <IEnumerable <GetCheeseResponse> >(allCheeseEntity));
            }
        }