Exemplo n.º 1
0
        public async IAsyncEnumerable <BasketDto> GetAll()
        {
            var entities = await _dbContext
                           .Baskets
                           .Include(basket => basket.BasketLines)
                           .ToListAsync()
            ;

            foreach (var entity in entities)
            {
                var dto = BasketDtoMapper.From(entity);
                yield return(dto);
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult <BasketDto> > CreateBasket(BasketForCreation basketForCreation)
        {
            var entity = new Basket
            {
                Id          = Guid.NewGuid().ToDbStringId(),
                UserId      = basketForCreation.UserId,
                BasketLines = new List <BasketLine>(),
            };
            await _dbContext.Baskets.AddAsync(entity);

            await _dbContext.SaveChangesAsync();

            var dto = BasketDtoMapper.From(entity);

            return(CreatedAtRoute("GetBasket", new { basketId = entity.Id }, dto));
        }
Exemplo n.º 3
0
        [HttpGet("{basketId}", Name = "GetBasket")] // CreatedAtRoute() 메소드에서 사용할 수 있는 Name
        public async Task <ActionResult <BasketDto> > GetBasket(string basketId)
        {
            var entity = await _dbContext
                         .Baskets
                         .Include(basket => basket.BasketLines)
                         .Where(basket => basket.Id == basketId)
                         .FirstOrDefaultAsync()
            ;

            if (entity == null)
            {
                return(NotFound());
            }

            var dto = BasketDtoMapper.From(entity);

            return(Ok(dto));
        }