public async Task <IActionResult> PutProduct(int id, Product product)
        {
            if (id != product.ProductId)
            {
                Console.WriteLine(id);
                return(BadRequest());
            }

            _context.Entry(product).State = EntityState.Modified;
            _context.Entry(product).Property("ProductId").IsModified = false;
            _context.Entry(product).Property("ShopId").IsModified    = false;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutCart(int id, Cart cart)
        {
            if (id != cart.CartId)
            {
                return(BadRequest());
            }

            //_context.Entry(cart).State = EntityState.Modified;
            _context.Entry(cart).Property("Qty").IsModified = true;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CartExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PutLogin(string id, Login login)
        {
            if (id != login.UserName)
            {
                return(BadRequest());
            }

            //_context.Entry(login).State = EntityState.Modified;
            _context.Entry(login).Property("Email").IsModified = true;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LoginExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 4
0
        public async Task <ActionResult <Shop> > PostShop(Shop shop)
        {
            _context.Shops.Add(shop);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetShop", new { id = shop.ShopId }, shop));
        }
Exemplo n.º 5
0
        public async Task <ActionResult <Order> > PostOrder(Order order)
        {
            _context.Orders.Add(order);
            await _context.SaveChangesAsync();

            await _context.Carts.Where(cart => (cart.UserName == order.UserName && cart.OrderId == null)).Include(c => c.Product).ForEachAsync(
                cart => {
                cart.OrderId        = order.OrderId;
                cart.Product.Stock -= cart.Qty;
                _context.Entry(cart.Product).Property("Stock").IsModified = true;
                _context.Entry(cart).Property("OrderId").IsModified       = true;
            }
                );

            await _context.SaveChangesAsync();

            return(Created("GetOrder", order));
        }