コード例 #1
0
ファイル: BuyService.cs プロジェクト: MesmeRamirez/StoreAPI
        public async Task <bool> Create(UserPerProductCreateDto model)
        {
            var result = false;

            try
            {
                var product = await _context.Product.SingleAsync(x => x.Id == model.ProductId);

                product.Quantity = product.Quantity - model.Quantity;
                _context.Update(product);
                await _context.SaveChangesAsync();

                _context.UserPerProduct.Add(new CUserPerProduct
                {
                    UserId     = model.UserId,
                    ProductId  = model.ProductId,
                    Quantity   = model.Quantity,
                    UpdateDate = DateTime.Now
                });

                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
            }

            return(result);
        }
コード例 #2
0
 public async Task <IActionResult> Create([FromBody] UserPerProductCreateDto model)
 {
     return(Ok(await _buyService.Create(model)));
 }