Beispiel #1
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 #2
0
        public Customer Update(Customer customerUpdate)
        {
            _ctx.Attach(customerUpdate).State = EntityState.Modified;
            _ctx.Entry(customerUpdate).Collection(c => c.Carts).IsModified = true;
            var carts = _ctx.Cart.Where(o => o.Customer.Id == customerUpdate.Id &&
                                        !customerUpdate.Carts.Exists(co => co.Id == o.Id));

            foreach (var cart in carts)
            {
                cart.Customer = null;
                _ctx.Entry(cart).Reference(o => o.Customer)
                .IsModified = true;
            }
            _ctx.SaveChanges();
            return(customerUpdate);
        }