public shoppingBagViewModel AddItemToShoppingBag(int shoppingBagId, int customerId, int productId, int quantity) { ShoppingBag shoppingBag = null; if (shoppingBagId == 0) { //Check if there is a shopping bag. If not create one and register it in the DB shoppingBag = new ShoppingBag(); shoppingBag.CId = customerId; shoppingBag.SBDate = DateTime.Now.Date; AddShoppingBag(shoppingBag); shoppingBagId = FindLastShoppingBagId(); shoppingBag.SBId = shoppingBagId; } //Here we add a shopping item and register it in the DB ShoppingItem shoppingItem = new ShoppingItem(); shoppingItem.SBId = shoppingBagId; shoppingItem.PId = productId; shoppingItem.SIQuantity = quantity; shoppingItemRepository.Add(shoppingItem); // create a new view so that all information can be transfered to the view shoppingBagViewModel bag = new shoppingBagViewModel(); bag.shoppingBag = shoppingBag; bag.shoppingItems.Add(shoppingItem); return(bag); }
public ShoppingBag AddItem2ShoppingBag(int shoppingBagId, int customerId, int productId, int quantity) { ShoppingBag shoppingBag = null; if (shoppingBagId == 0) { //Nieuwe shoppingBag shoppingBag = new ShoppingBag { CustomerId = 1,//customerId, Date = DateTime.Now.Date }; Add(shoppingBag); shoppingBagId = FindLastId(); shoppingBag.ShoppingBagId = shoppingBagId; } //add product to shoppingitem ShoppingItem shoppingItem = new ShoppingItem(); shoppingItem.ShoppingBagId = shoppingBagId; shoppingItem.ProductId = 1;//productId; shoppingItem.Quantity = quantity; //shoppingitem toevoegen aan database shoppingItemRepository.Add(shoppingItem); return(shoppingBag); }
public void AddShoppingItem(ShoppingItem shoppingItem) { repository.Add(shoppingItem); }