public List <Product> GetAllProductsByOrderDetail(Business.Library.OrderDetails od) { List <Products> entity = _context.Products.Include(p => p.OrderDetails).ToList(); entity = entity.Where(p => p.Id == od.product_id).ToList(); return(entity.Select(Mapper.MapProduct).ToList()); }
public static Entities.OrderDetails MapOrderDetails(Business.Library.OrderDetails order) { return(new Entities.OrderDetails { //Order = MapOrder(order.Order), //Product = MapProduct(order.Product), //OrderDetailId = order.ID, OrderId = order.Order.ID, ProductId = order.Product.ID, Quantity = order.Quantity }); }
public void AddNewOrderDetail(Business.Library.OrderDetails order) { Business.Library.OrderDetails od = new Business.Library.OrderDetails { order_id = order.order_id, product_id = order.product_id, Quantity = order.Quantity, //Product = product, //Order = order }; Entities.OrderDetails entity = Mapper.MapOrderDetails(od); _context.Add(entity); }
public static void UpdateOrder(Repository data, Order order, Business.Library.Inventory inv) { //List<Business.Library.Order> entityOrder = data.GetOrders(order.OCustomer, order.OLocation); Business.Library.OrderDetails od = new Business.Library.OrderDetails(); //od.order_id = entityOrder[0].ID; //od.Order = entityOrder[0]; od.product_id = inv.Product.ID; od.Quantity = inv.quantity; od.Product = inv.Product; Console.WriteLine($"Updating od: order_id = {od.order_id}, product_id = {od.product_id}, quantity = {od.Quantity}"); data.AddNewOrderDetail(od); data.Save(); }
public static List <Product> AddToCart(Business.Library.Inventory invItem, int quantity, Location location, Repository data, List <Product> cart) { Business.Library.OrderDetails od = new Business.Library.OrderDetails(); try { invItem.Product = new Product(invItem.Product.Name, invItem.Product.Description, invItem.Product.Price); } catch (ArgumentNullException) { Console.WriteLine("Product does not exist try again."); return(cart); } int index; //Console.WriteLine($"Location: {_location.LocationName}"); //Console.WriteLine($"Index => {index}"); //Console.WriteLine($"Item {item.Name}, quantity: {_location.Inventory[index].Amount} "); //Console.WriteLine(_location.Quantity(product)); //Console.WriteLine("Removing item from inventory"); //_location.RemoveItem(product, quantity); //Console.WriteLine($"Quantity now {_location.Quantity(product)}"); if (location.Quantity(invItem) >= quantity) { cart.Add(invItem.Product); Console.WriteLine($"Added {invItem.Product.Name} to cart."); index = cart.IndexOf(invItem.Product); invItem.quantity -= quantity; data.UpdateLocationInventory(invItem); data.Save(); cart[index].Amount += quantity; return(cart); } else if (location.Quantity(invItem) == 0) { Console.WriteLine($"{invItem.Product.Name} is sold out!"); return(cart); } else { Console.WriteLine($"There is only {location.Quantity(invItem)} left. " + $"Please decrease quantity."); return(cart); } }
public void AddNewOrderDetail(Business.Library.OrderDetails order) { Entities.OrderDetails entity = Mapper.MapOrderDetails(order); _context.Add(entity); }
public void UpdateCartForOrder(Business.Library.OrderDetails order) { Entities.OrderDetails myEntity = _context.OrderDetails.Find(order.ID); Entities.OrderDetails newEntity = Mapper.MapOrderDetails(order); _context.Entry(myEntity).CurrentValues.SetValues(newEntity); }