private UserOrderItem GetParcelCost(UserOrderItem userOrderItem) { ++orderNumber; if (userOrderItem.ShippingDetail.ParcelSize == Size.Small) { ++smallNumber; if (smallNumber == 4) { userOrderItem.ShippingDetail.Cost = 0; } } if (userOrderItem.ShippingDetail.ParcelSize == Size.Small) { ++meduimNumber; if (meduimNumber == 3) { userOrderItem.ShippingDetail.Cost = 0; } } if (orderNumber == 5) { userOrderItem.ShippingDetail.Cost = 0; } return(userOrderItem); }
//return an instance of an user order item to the cart so that it can be stored into a list in session public UserOrderItem CreateUserOrderItem(int itemId, int?orderId, int quantity) { var storeItem = _context.StoreItems.First(x => x.StoreItemId == itemId); var order = _context.UserOrders.First(x => x.UserOrderId == orderId); UserOrderItem newOrderItem = new UserOrderItem { StoreItem = storeItem, UserOrder = order, OrderQuantity = quantity }; return(newOrderItem); }
public List <UserOrderItem> getOrderItems(Order order) { List <UserOrderItem> items = new List <UserOrderItem>(); foreach (OrderItem orderItem in order.getOrderItems()) { InventoryItem inventoryItem = InventoryManager.getSingleItem(orderItem.getProductId()); UserOrderItem item = new UserOrderItem(); item.itemCost = orderItem.getSalePrice(); item.itemCount = orderItem.getCount(); item.itemName = inventoryItem.getProductName(); item.itemShortDescription = inventoryItem.getShortDescription(); items.Add(item); } return(items); }
public List <UserOrderItem> Calculate(List <UserOrderItem> userOrderItems) { decimal cost = 0; foreach (var userOrderItem in userOrderItems) { cost += userOrderItem.GetCost(); } var userItem = new UserOrderItem(cost) { ShippingDetail = new ShippingDetail(Size.None, 0) { Cost = cost } }; userOrderItems.Add(userItem); return(userOrderItems); }
private UserOrderItem GetParcelCost(UserOrderItem userOrderItem) { decimal cost = 0; decimal maxWeight = 0; decimal defaultAdditionalCost = 2; switch (userOrderItem.ShippingDetail.ParcelSize) { case Size.Xll: cost = 50; maxWeight = 50; defaultAdditionalCost = 1; break; case Size.Xl: cost = 25; maxWeight = 10; break; case Size.Large: cost = 15; maxWeight = 6; break; case Size.Medium: cost = 8; maxWeight = 3; break; case Size.Small: cost = 3; maxWeight = 1; break; } userOrderItem.ShippingDetail.Cost = cost + CalculateAdditionalCost(maxWeight, userOrderItem.ShippingDetail.Weight, defaultAdditionalCost); return(userOrderItem); }
private List<UserOrderItem> getUserOrderItems(Order order) { List<UserOrderItem> userOrderItems = new List<UserOrderItem>(); foreach (OrderItem orderItem in order.getOrderItems()) { UserOrderItem item = new UserOrderItem(); item.itemCost = orderItem.getSalePrice(); item.itemCount = orderItem.getCount(); InventoryItem inventoryItem = InventoryManager.getSingleItem(orderItem.getProductId()); item.itemName = inventoryItem.getProductName(); item.itemShortDescription = inventoryItem.getShortDescription(); userOrderItems.Add(item); } return userOrderItems; }
public void TestCreateUserOrderItem() { //Arrange var options = new DbContextOptionsBuilder <Project1Context>() .UseInMemoryDatabase(databaseName: "Test13") .Options; UserInfo userInfo = new UserInfo() { fName = "David", lName = "Leblanc", userName = "******", password = "******" }; StoreLocation storeLocation = new StoreLocation() { Location = "Houston" }; StoreItem storeItem = new StoreItem() { itemName = "Chicken", itemPrice = 5 }; StoreItemInventory storeItemInventory = new StoreItemInventory() { itemInventory = 10 }; UserOrder userOrder = new UserOrder() { StoreLocation = storeLocation, UserInfo = userInfo, timeStamp = DateTime.Now }; UserOrderItem userOrderItem = new UserOrderItem() { StoreItem = storeItem, UserOrder = userOrder, OrderQuantity = 2 }; List <UserOrderItem> listItems = new List <UserOrderItem>() { userOrderItem }; storeItem.StoreItemInventory = storeItemInventory; string orderss; //Act using (var db3 = new Project1Context(options)) { storeItem.StoreLocation = storeLocation; db3.AddRange(storeLocation, storeItem, userOrder, userOrderItem, storeItemInventory); db3.SaveChanges(); var newStoreItem = db3.StoreItems.First(x => x.StoreItemId == 1); var order = db3.UserOrders.First(x => x.UserOrderId == 1); UserOrderItem newOrderItem = new UserOrderItem { StoreItem = storeItem, UserOrder = order, OrderQuantity = 2 }; db3.Add(newOrderItem); db3.SaveChanges(); orderss = db3.UserOrderItems.Include(x => x.StoreItem).First().StoreItem.itemName; } //Assert using (var db3 = new Project1Context(options)) { //check if the created user order item is stored in the database Assert.Equal("Chicken", orderss); } }
public void TestGetAllOrderByUserId() { //Arrange var options = new DbContextOptionsBuilder <Project1Context>() .UseInMemoryDatabase(databaseName: "Test11") .Options; UserInfo userInfo = new UserInfo() { fName = "David", lName = "Leblanc", userName = "******", password = "******" }; StoreLocation storeLocation = new StoreLocation() { Location = "Houston" }; StoreItem storeItem = new StoreItem() { itemName = "Chicken", itemPrice = 5 }; StoreItemInventory storeItemInventory = new StoreItemInventory() { itemInventory = 10 }; UserOrder userOrder = new UserOrder() { StoreLocation = storeLocation, UserInfo = userInfo, timeStamp = DateTime.Now }; UserOrderItem userOrderItem = new UserOrderItem() { StoreItem = storeItem, UserOrder = userOrder, OrderQuantity = 2 }; List <UserOrderItem> listItems = new List <UserOrderItem>() { userOrderItem }; storeItem.StoreItemInventory = storeItemInventory; IEnumerable <UserOrder> orders; string orderss; //Act using (var db3 = new Project1Context(options)) { storeItem.StoreLocation = storeLocation; db3.AddRange(storeLocation, storeItem, userOrder, userOrderItem, storeItemInventory); db3.SaveChanges(); orders = db3.UserOrders .Include(x => x.UserOrderItems).ThenInclude(x => x.StoreItem) .Where(x => x.UserInfo.UserInfoId == 1); orderss = orders.First().UserOrderItems.First().StoreItem.itemName; } //Assert using (var db3 = new Project1Context(options)) { //checks to make sure that the user order item name is correct Assert.Equal("Chicken", orderss); } }
public void TestUpdateInventoryQuantity() { //Arrange var options = new DbContextOptionsBuilder <Project1Context>() .UseInMemoryDatabase(databaseName: "Test9") .Options; UserInfo userInfo = new UserInfo() { fName = "David", lName = "Leblanc", userName = "******", password = "******" }; StoreLocation storeLocation = new StoreLocation() { Location = "Houston" }; StoreItem storeItem = new StoreItem() { itemName = "Chicken", itemPrice = 5 }; StoreItemInventory storeItemInventory = new StoreItemInventory() { itemInventory = 10 }; UserOrder userOrder = new UserOrder() { StoreLocation = storeLocation, UserInfo = userInfo, timeStamp = DateTime.Now }; UserOrderItem userOrderItem = new UserOrderItem() { StoreItem = storeItem, UserOrder = userOrder, OrderQuantity = 2 }; List <UserOrderItem> listItems = new List <UserOrderItem>() { userOrderItem }; storeItem.StoreItemInventory = storeItemInventory; int updatedInventory; //Act using (var db3 = new Project1Context(options)) { storeItem.StoreLocation = storeLocation; db3.AddRange(storeLocation, storeItem, userOrder, userOrderItem, storeItemInventory); db3.SaveChanges(); //goes throught the list of item user selected for an order. //access the store inventory and subtract user order quantity from it. foreach (UserOrderItem x in listItems) { var itemInventory = db3.StoreItems.Include(a => a.StoreItemInventory) .First(t => t.StoreItemId == 1); itemInventory.StoreItemInventory.itemInventory -= x.OrderQuantity; } db3.SaveChanges(); //retrieves the updated store item inventory for chicken updatedInventory = db3.StoreItems.Include(x => x.StoreItemInventory).First(x => x.StoreItemId == 1) .StoreItemInventory.itemInventory; } //Assert using (var db3 = new Project1Context(options)) { //if function works properly the updated inventory should be 8 as it was 10 before and user ordered 2 Assert.Equal(8, updatedInventory); } }