public async Task <ActionResult <Basket> > Post(BasketForCreation basketForCreation)
        {
            var basketEntity = mapper.Map <Entities.Basket>(basketForCreation);

            basketRepository.AddBasket(basketEntity);
            await basketRepository.SaveChanges();

            var basketToReturn = mapper.Map <Basket>(basketEntity);

            return(CreatedAtRoute(
                       "GetBasket",
                       new { basketId = basketEntity.BasketId },
                       basketToReturn));
        }
Exemple #2
0
        public async Task <ActionResult <Basket> > Post(BasketForCreation basket)
        {
            var entity = _mapper.Map <Entities.Basket>(basket);

            _repository.AddBasket(entity);
            await _repository.SaveChanges();

            var model = _mapper.Map <Basket>(entity);

            return(CreatedAtRoute(
                       "GetBasket",
                       new { basketId = entity.BasketId },
                       model));
        }
Exemple #3
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));
        }