public void RemoveAllFromCart(Pie pie)
        {
            var shoppingCartItem =
                _appDbContext.ShoppingCartItems.SingleOrDefault(
                    s => s.Pie.PieId == pie.PieId && s.ShoppingCartId == ShoppingCartId);

            if (shoppingCartItem != null)
            {
                _appDbContext.ShoppingCartItems.Remove(shoppingCartItem);
            }

            _appDbContext.SaveChanges();
        }
        public int RemoveFromCart(Pie pie)
        {
            var shoppingCartItem =
                _appDbContext.ShoppingCartItems.SingleOrDefault(
                    s => s.Pie.PieId == pie.PieId && s.ShoppingCartId == ShoppingCartId);

            var localAmount = 0;

            if (shoppingCartItem != null)
            {
                _appDbContext.ShoppingCartItems.Remove(shoppingCartItem);
            }

            _appDbContext.SaveChanges();

            return(localAmount);
        }
Beispiel #3
0
        public void RemoveFromCart(Pie pie)
        {
            ShoppingCartItem shoppingCartItem = _appDbContext.ShoppingCartItems.SingleOrDefault(item => item.Pie.PieId == pie.PieId);

            if (shoppingCartItem != null)
            {
                if (shoppingCartItem.Amount > 0)
                {
                    shoppingCartItem.Amount--;
                }
                else
                {
                    _appDbContext.ShoppingCartItems.Remove(shoppingCartItem);
                }
                _appDbContext.SaveChanges();
            }
        }
        public int RemoveFromOrder(Pie pie)
        {
            OrderItem itemToRemove = _context.OrderItems.SingleOrDefault(i => i.Pie.Id == pie.Id && i.OrderId == Id);

            if (itemToRemove != null)
            {
                if (itemToRemove.Quantity > 1)
                {
                    itemToRemove.Quantity--;
                }
                else
                {
                    _context.OrderItems.Remove(itemToRemove);
                }
            }
            _context.SaveChanges();
            return(itemToRemove.Quantity);
        }
        public void AddToCart(Pie pie, int count)
        {
            var item = this._context.ShoppingCartItems.SingleOrDefault(i => i.Pie.Id == pie.Id && i.CartId == this.Id);

            if (item == null)
            {
                item = new ShoppingCartItem {
                    Pie = pie, Count = 1, CartId = this.Id
                };
                this._context.ShoppingCartItems.Add(item);
            }
            else
            {
                item.Count++;
            }

            this._context.SaveChanges();
        }
        public void AddToOrder(Pie pie)
        {
            OrderItem itemToAdd = _context.OrderItems.SingleOrDefault(i => i.Pie.Id == pie.Id && i.OrderId == Id);

            if (itemToAdd == null)
            {
                itemToAdd = new OrderItem()
                {
                    OrderId = Id, Pie = pie, Quantity = 1
                };
                _context.OrderItems.Add(itemToAdd);
            }
            else
            {
                itemToAdd.Quantity++;
            }
            _context.SaveChanges();
        }
        public void AddToCart(Pie pie, int amount)
        {
            var shoppingCartItem = _appDbContext.ShoppingCartItems.SingleOrDefault(s => s.Pie.PieId == pie.PieId && s.ShoppingCartId == ShoppingCartId);

            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    Pie            = pie,
                    Amount         = 1
                };
                _appDbContext.ShoppingCartItems.Add(shoppingCartItem);
            }
            else
            {
                shoppingCartItem.Amount++;
            }
            _appDbContext.SaveChanges();
        }
        public int RemoveFromCart(Pie pie)
        {
            var item       = this._context.ShoppingCartItems.SingleOrDefault(i => i.Pie.Id == pie.Id && i.CartId == this.Id);
            var localCount = 0;

            if (item != null)
            {
                if (item.Count > 1)
                {
                    item.Count--;
                    localCount = item.Count;
                }
                else
                {
                    this._context.ShoppingCartItems.Remove(item);
                }

                this._context.SaveChanges();
            }

            return(localCount);
        }
        public int RemoveFromCard(Pie pie)
        {
            var shoppingCartItem =
                _appDbContext.ShoppingCartItems.SingleOrDefault(s =>
                                                                s.Pie.PieId == pie.PieId && s.ShoppingCartId == ShoppingCartId);
            int localAmount = 0;

            if (shoppingCartItem != null)
            {
                if (shoppingCartItem.Amount > 1)
                {
                    shoppingCartItem.Amount--;
                    localAmount = shoppingCartItem.Amount;
                }
                else
                {
                    _appDbContext.ShoppingCartItems.Remove(shoppingCartItem);
                }
            }

            _appDbContext.SaveChanges();
            return(localAmount);
        }
Beispiel #10
0
        public void AddToCart(Pie pie, int amount)
        {
            var shoppingCartItem =
                _appDbContext.ShoppingCartItems.SingleOrDefault(
                    s => s.Pie.PieId == pie.PieId && s.ShoppingCartId == ShoppingCartId);

            // If the pie is not in the shopping cart, add it.  Else update the number of ordered pies
            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    Pie            = pie,
                    Amount         = 1
                };

                _appDbContext.ShoppingCartItems.Add(shoppingCartItem);
            }
            else
            {
                shoppingCartItem.Amount++;
            }
            _appDbContext.SaveChanges();
        }
        public void AddToCart(Pie pie, int amount)
        {
            var shoppingCartItem =
                _mockPieRepository.ShoppingCartItems.SingleOrDefault(
                    s => s.Pie.PieId == pie.PieId && s.ShoppingCartId == ShoppingCartId);

            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    Pie            = pie,
                    Amount         = 1
                };

                //  _mockPieRepository.ShoppingCartItems.Add(shoppingCartItem);
                ShoppingCartItems1.Add(shoppingCartItem);
            }
            else
            {
                shoppingCartItem.Amount++;
            }
            // _appDbContext.SaveChanges(); not required as not saving anywhere
        }
Beispiel #12
0
        public void AddToCart(Pie pie, int amount) //potential bug; amount isnt used
        {
            var shoppingCartItem =
                _appDbContext.ShoppingCartItems.SingleOrDefault(
                    s => s.Pie.PieId == pie.PieId && s.ShoppingCartId == ShoppingCartId);

            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    Pie            = pie,
                    Amount         = 1
                };

                _appDbContext.ShoppingCartItems.Add(shoppingCartItem);
            }
            else
            {
                shoppingCartItem.Amount++; //amount probably should be used here
                                           //shoppingCartItem.Amount += amount
            }
            _appDbContext.SaveChanges();
        }
 public void CreatePie(Pie pie)
 {
     _appDbContext.Pies.Add(pie);
     _appDbContext.SaveChanges();
 }
Beispiel #14
0
 public void UpdatePie(Pie pie)
 {
     throw new NotImplementedException();
 }
 public void AddPie(Pie pie)
 {
     _appDbContext.Pies.Add(pie);
 }
 public void AddPie(Pie pie)
 {
     _appDbContext.Add(pie);
     _appDbContext.SaveChanges();
 }
 public void UpdatePie(Pie pie)
 {
     _appDbContext.Pies.Update(pie);
 }
Beispiel #18
0
 public void Update(Pie pie)
 {
     _appDbContext.Pies.Update(pie);
     _appDbContext.SaveChanges();
 }
 public Pie AddPie(Pie pie)
 {
     throw new NotImplementedException();
 }