예제 #1
0
        public async Task <IActionResult> PutCartItems(int id, CartItems cartItems)
        {
            if (id != cartItems.Id)
            {
                return(BadRequest());
            }

            _context.Entry(cartItems).State = EntityState.Modified;

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

            return(NoContent());
        }
        public async Task <IActionResult> PutCarts([FromRoute] int id, [FromBody] Carts carts)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != carts.Id)
            {
                return(BadRequest());
            }

            _context.Entry(carts).State = EntityState.Modified;

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

            return(NoContent());
        }
 public async Task AddItem(ShoppingCart shoppingCart, ShoppingCartItem newItem)
 {
     if (shoppingCart.Items.Any(i => i.ExternalId == newItem.ExternalId))
     {
         var item = shoppingCart.Items.Single(i => i.ExternalId == newItem.ExternalId);
         item.ExternalSource        = newItem.ExternalSource;
         item.Contents              = newItem.Contents;
         item.UnitPrice             = newItem.UnitPrice;
         item.Quantity             += newItem.Quantity;
         _context.Entry(item).State = EntityState.Modified;
         await _context.SaveChangesAsync();
     }
     else
     {
         shoppingCart.Items.Add(newItem);
         await _context.SaveChangesAsync();
     }
 }
예제 #4
0
 public ActionResult Edit([Bind(Include = "id,UserName,itemId,itemName,itemImageUrl,itemPrice")] Cart cart)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cart).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cart));
 }
 public ActionResult Edit([Bind(Include = "ProductID,Name,Price,Quantity")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
예제 #6
0
        public async Task <IActionResult> PutCartItem(int id, CartItem item)
        {//204(No Content)
            if (id != item.id)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
예제 #7
0
        public IHttpActionResult PutCarts(int id, Carts carts)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != carts.Id)
            {
                return(BadRequest());
            }

            var userId = User.Identity.GetUserId();

            if (userId != carts.UserId)
            {
                return(StatusCode(HttpStatusCode.Conflict));
            }
            db.Entry(carts).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CartsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #8
0
 public void Update(T entity)
 {
     _dbContext.Entry(entity).State = EntityState.Modified;
 }