Ejemplo n.º 1
0
        public async Task <bool> CheckOutCartProductsAsync(List <CartCheckoutDto> cartItemsList)
        {
            try
            {
                bool result = true;
                foreach (var item in cartItemsList)
                {
                    var product = await _context.Products.FindAsync(item.ProductId);

                    if (product.Quantity - item.Quantity < 0)
                    {
                        result = false;
                        break;
                    }
                    product.Quantity -= item.Quantity;
                    _context.Entry(product).State = EntityState.Modified;
                }
                await _context.SaveChangesAsync();

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutProductsModel(int id, ProductsModel ProductsModel)
        {
            ProductsModel.IdProduct = id;

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

            if (id != ProductsModel.IdProduct)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PutProduct([FromRoute] Guid id, [FromBody] Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != product.Id)
            {
                return(BadRequest("Product id is required"));
            }

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

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

            return(Ok("Product updated " + product.Id));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PutOrderModel(int id, OrderModel OrderModel)
        {
            if (id != OrderModel.IdOrder)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "ProductId,Name,Price")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
Ejemplo n.º 6
0
 public ActionResult Edit(Products products)
 {
     if (ModelState.IsValid)
     {
         db.Entry(products).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(products));
 }
Ejemplo n.º 7
0
        public ActionResult Edit(Product entity)
        {
            var Types      = db.Types.ToList();
            var selectlist = new SelectList(Types, "Id", "Caption");

            ViewBag.Types = selectlist;

            db.Entry(entity).State = System.Data.Entity.EntityState.Modified;

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }