Beispiel #1
0
 public ActionResult <Core.Entity.Cart> Post([FromBody] Core.Entity.Cart order)
 {
     try
     {
         return(Ok(_cartService.CreateCart(order)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Beispiel #2
0
        public Cart Create(Core.Entity.Cart cart)
        {
            int noStockProduct = IsStockAvailable(cart.CartLines);

            if (noStockProduct > 0)
            {
                throw new Exception($"{noStockProduct} idli ürün stokta yok!");
            }

            _ctx.Attach(cart).State = EntityState.Added;
            _ctx.SaveChanges();
            return(cart);
        }
Beispiel #3
0
        public ActionResult <Core.Entity.Cart> Put(int id, [FromBody] Core.Entity.Cart cart)
        {
            if (id < 1 || id != cart.Id)
            {
                return(BadRequest("Parametre Id ile sepet Id aynı olmalıdır!"));
            }

            try
            {
                return(Ok(_cartService.UpdateCart(cart)));
            }
            catch (Exception e)
            {
                return(StatusCode(403, e.Message));
            }
        }
Beispiel #4
0
        public Cart Update(Core.Entity.Cart cartUpdate)
        {
            int noStockProduct = IsStockAvailable(cartUpdate.CartLines);

            if (noStockProduct > 0)
            {
                throw new Exception($"{noStockProduct} idli ürün stokta yok!");
            }

            var newCartLines = new List <CartLine>(cartUpdate.CartLines);

            _ctx.Attach(cartUpdate).State = EntityState.Modified;
            _ctx.CartLines.RemoveRange(
                _ctx.CartLines.Where(ol => ol.CartId == cartUpdate.Id)
                );
            foreach (var ol in newCartLines)
            {
                _ctx.Entry(ol).State = EntityState.Added;
            }
            _ctx.Entry(cartUpdate).Reference(o => o.Customer).IsModified = true;
            _ctx.SaveChanges();
            return(cartUpdate);
        }