Exemple #1
0
        public void EditPie(Pie the_pie, Pie pie)
        {
            the_pie.PieName          = pie.PieName;
            the_pie.PiePhoto         = pie.PiePhoto;
            the_pie.Price            = pie.Price;
            the_pie.ShortDescreption = pie.ShortDescreption;
            the_pie.LongDescreption  = pie.LongDescreption;
            the_pie.CategoryId       = pie.CategoryId;

            _appDbContext.SaveChanges();
        }
        public void CreatePie(Pie pie)
        {
            StockItem stockItem = new StockItem()
            {
                id    = pie.PieId,
                name  = pie.PieName,
                Price = pie.Price
            };

            _appDbContext.stockItems.Add(stockItem);
            _appDbContext.Pies.Add(pie);
            _appDbContext.SaveChanges();
        }
        public void EditPie(Pie the_pie, Pie pie)
        {
            StockItem stockItem = stockItemRepository.GetStockItemByName(the_pie.PieName);

            stockItem.name           = pie.PieName;
            stockItem.Price          = pie.Price;
            the_pie.PieName          = pie.PieName;
            the_pie.PiePhoto         = pie.PiePhoto;
            the_pie.Price            = pie.Price;
            the_pie.ShortDescreption = pie.ShortDescreption;
            the_pie.LongDescreption  = pie.LongDescreption;
            the_pie.CategoryId       = pie.CategoryId;

            _appDbContext.SaveChanges();
        }
Exemple #4
0
        public int RemoveFromCart(Pie pie)
        {
            var removedItem = _appDbContext.ShoppingCartItems
                              .SingleOrDefault(s => s.ShoppingCartId == ShoppingCartId && s.Pie == pie);
            var localAmount = 0;

            if (removedItem != null)
            {
                if (removedItem.Amount > 1)
                {
                    localAmount = --removedItem.Amount;
                }
                else
                {
                    _appDbContext.ShoppingCartItems.Remove(removedItem);
                }
            }
            _appDbContext.SaveChanges();
            return(localAmount);
        }
Exemple #5
0
        public int RemoveFromCart(Pie pie)
        {
            var shoppingCartItem = _pieDbContext.ShoppingCartItems.SingleOrDefault(s => s.Pie.Id == pie.Id && s.ShoppingCartId == ShoppingCartId);
            var localAmount      = 0;

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

            _pieDbContext.SaveChanges();
            return(localAmount);
        }
Exemple #6
0
        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();
        }
Exemple #7
0
        public void AddToCart(Pie pie, int amount)
        {
            var itemsInCart = _appDbContext.ShoppingCartItems.SingleOrDefault(
                s => s.Pie.PieId == pie.PieId && s.ShoppingCartId == ShoppingCartId);

            if (itemsInCart == null)
            {
                itemsInCart = new ShoppingCartItem()
                {
                    ShoppingCartId = ShoppingCartId,
                    Pie            = pie,
                    Amount         = 1
                };
                _appDbContext.ShoppingCartItems.Add(itemsInCart);
            }
            else
            {
                itemsInCart.Amount += amount;
            }

            _appDbContext.SaveChanges();
        }
        //Return an int for the amount of pie leftover that the user selected after removing one
        public int RemoveFromCart(Pie pie)
        {
            //Grab the appDbContext.ShoppingCartItems dbset and return the first pie  where the DBset shoppingCartItem.Pie.id is equal to the passed in pie.id and the
            //shoppingCartItem.ShoppingCartId(SessionId) is the current session(ShoppingCartId)
            // If no pie was found in session ShoppingCartItem list returns null
            var shoppingCartItem =
                _appDbContext.ShoppingCartItems.SingleOrDefault(
                    s => s.Pie.PieId == pie.PieId && s.ShoppingCartId == ShoppingCartId);

            //Container to hold the amount of that certain pie after we remove one
            var localAmount = 0;

            //If Pie was found
            if (shoppingCartItem != null)
            {
                //If more than one of those pie was found
                if (shoppingCartItem.Amount > 1)
                {
                    //decrease the ammount attribute by 1 pie in ShoppingCartItem instance
                    shoppingCartItem.Amount--;

                    // set the amount to be equal
                    localAmount = shoppingCartItem.Amount;
                }
                else
                {
                    //If that pie has an amount of 1 we remove the pie from ShoppingCartItems DBSet
                    _appDbContext.ShoppingCartItems.Remove(shoppingCartItem);
                }
            }

            //Save the change
            _appDbContext.SaveChanges();

            //Return amount of that Pie leftover in our shopping cart
            return(localAmount);
        }
Exemple #9
0
        // Adds the item to the current ShoppingCart
        public void AddToCart(Pie pie, int amount)
        {
            var shoppingCartItem = _appDbContext.ShoppingCartItems.SingleOrDefault(s => s.Pie.PieId == pie.PieId && s.ShoppingCartId == ShoppingCartId);

            // DOUBTS!
            // If the current item already exists in the shopping cart, ads +1 to the amount. If not, creates a new one.
            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartId = ShoppingCartId,
                    Pie            = pie,
                    Amount         = 1
                };

                _appDbContext.ShoppingCartItems.Add(shoppingCartItem);
            }
            else
            {
                shoppingCartItem.Amount++;
            }

            _appDbContext.SaveChanges();
        }
Exemple #10
0
 public void UpdatePie(Pie pie)
 {
     throw new NotImplementedException();
 }
Exemple #11
0
 public void CreatePie(Pie pie)
 {
     _appDbContext.Pies.Add(pie);
     _appDbContext.SaveChanges();
 }
Exemple #12
0
 public void UpdatePie(Pie pie)
 {
     _appDbContext.Pies.Update(pie);
     _appDbContext.SaveChanges();
 }
 public void CreatePie(Pie pie)
 {
     throw new System.NotImplementedException();
 }
 public void MakePieOfTheWeek(Pie pie)
 {
     pie.PiesOfTheWeek = true;
     _appDbContext.SaveChanges();
 }
 public void RemovePie(Pie pie)
 {
     _appDbContext.Pies.Remove(pie);
     _appDbContext.SaveChanges();
 }