예제 #1
0
        public async Task <Option <CartItemServiceModel, Error> > CreateAsync(CartItemBm model)
        {
            model.CartId = await GetCurrentCartIdByUserIdAsync(model.UserId);

            return(await ExistsAsync(model)
                ? Option.None <CartItemServiceModel, Error>(CartItemExistsErrMsg.ToError())
                : (await SaveAsync(model)).Some <CartItemServiceModel, Error>());
        }
예제 #2
0
        private async Task <CartItemServiceModel> SaveAsync(CartItemBm model)
        {
            var entity = Mapper.Map <CartItemBm, CartItem>(model);
            await DbContext.CartItems.AddAsync(entity);

            await DbContext.SaveChangesAsync();

            return(Mapper.Map <CartItem, CartItemServiceModel>(entity));
        }
예제 #3
0
 private async Task <bool> ExistsAsync(CartItemBm model)
 => await DbContext
 .CartItems
 .AnyAsync(ci => ci.CartId == model.CartId &&
           ci.ProductId == model.ProductId);
 public async Task <IActionResult> Create([FromBody] CartItemBm model)
 {
     model.UserId = User.Identity.GetUserId();
     return((await _cartItemsService.CreateAsync(model))
            .Match(ci => CreatedAtAction(nameof(Create), ci), ErrorContent));
 }