Beispiel #1
0
        public int AddToCart(cfcusaga.domain.Events.Item item)
        {

            try
            {
                var cartItem = new cfcusaga.domain.Orders.Cart
                {
                    ItemId = item.Id,
                    CartId = ShoppingCartId,
                    Count = 1,
                    DateCreated = DateTime.Now,
                    TshirtSize = item.TshirtSize
                };
                _svc.AddItemToCart(cartItem);

                //_svc.SaveChanges();
                return cartItem.Count;
            }
            catch (Exception ex)
            {

                throw;
            }
        }
Beispiel #2
0
        //public async Task<List<cfcusaga.domain.Orders.Cart>> GetCartItems()
        //{
        //    return await _svc.GetCartItems(ShoppingCartId);
        //}

        public cfcusaga.domain.Orders.Cart AddToCart(cfcusaga.domain.Events.Item item, out int count)
        {

            try
            {
                var cartItem = new cfcusaga.domain.Orders.Cart
                {
                    ItemId = item.Id,
                    CartId = ShoppingCartId,
                    Count = 1,
                    DateCreated = DateTime.Now
                };
                _svc.AddItemToCart(cartItem);

                int id = cartItem.Id;
                count = cartItem.Count;
                return cartItem;
            }
            catch (Exception ex)
            {

                throw;
            }
        }
 private async Task AddItemDiscount(Item foundItem, Cart currentCart)
 {
     var itemDiscount = await _db.Discounts.FirstOrDefaultAsync(d => d.ItemId == foundItem.Id);
     if (itemDiscount != null)
     {
         var itemCount = await _db.Carts.CountAsync(i => i.ItemId == foundItem.Id && i.CartId == currentCart.CartId);
         var cartDiscount = await _db.CartDiscounts.FirstOrDefaultAsync(
                     c => c.DiscountId == itemDiscount.Id && c.CartId == currentCart.CartId);
         if (itemCount >= itemDiscount.DiscountBeginAtNthItem)
         {
             if (cartDiscount != null)
             {
                 if (itemDiscount.DiscountBeginAtNthItem != null)
                     cartDiscount.Quantity = itemCount - (itemDiscount.DiscountBeginAtNthItem.Value - 1);
                         //cartDiscount.Quantity + 1;
             }
             else
             {
                 var newCartDiscount = _db.Set<cfcusaga.data.CartDiscount>().Create();
                 newCartDiscount.DiscountId = itemDiscount.Id;
                 if (itemDiscount.Price != null) newCartDiscount.Discount = itemDiscount.Price.Value;
                 newCartDiscount.CartId = currentCart.CartId;
                 if (itemDiscount.DiscountBeginAtNthItem != null)
                     newCartDiscount.Quantity = itemCount - (itemDiscount.DiscountBeginAtNthItem.Value - 1);
                 _db.CartDiscounts.Add(newCartDiscount);
             }
         }
         else
         {
             // something went wrong ???
             if (cartDiscount != null)
             {
                 if (itemDiscount.DiscountBeginAtNthItem != null)
                     cartDiscount.Quantity = itemCount - (itemDiscount.DiscountBeginAtNthItem.Value - 1);
                 if (cartDiscount.Quantity == 0)
                 {
                     _db.CartDiscounts.Remove(cartDiscount);
                 }
             }
         }
     }
 }