Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 public async Task <IActionResult> Create([FromBody] UserPerProductCreateDto model)
 {
     return(Ok(await _buyService.Create(model)));
 }