public void Add(string productCode) { if (string.IsNullOrWhiteSpace(productCode)) { throw new ArgumentNullException(nameof(productCode)); } var product = _productRepository.Find(productCode); if (product == null) { throw new Exception($"{productCode} does not exist."); } var existingItem = this[product]; if (existingItem == null) { this[product] = new ProductOrderDetails { Quantity = 1 }; } else { existingItem.Quantity++; } }
public bool DeleteProductOrderDetailsDAL(string productOrderID) { bool ProductOrderDeleted = false; try { ProductOrderDetails deleteProductOrder = null; foreach (ProductOrderDetails item in productorderList) { if (item.ProductOrderID == productOrderID) { deleteProductOrder = item; } } if (deleteProductOrder != null) { productorderList.Remove(deleteProductOrder); ProductOrderDeleted = true; } } catch (Exception ex) { throw new InventoryException(ex.Message); } return(ProductOrderDeleted); }
public bool AddProductOrderDetailsDAL(ProductOrderDetails orderdetail, List <ProductOrderDetails> orderDetails) { bool ProductorderDetailAdded = false; try { orderDetails.Add(orderdetail); ProductorderDetailAdded = true; } catch (Exception ex) { throw new InventoryException(ex.Message); } return(ProductorderDetailAdded); }
public InvoiceDetails Invoice(FinalOrder finalOrder) { int sum = 0; Orders orders = new Orders(); orders.CustomerId = finalOrder.CustomerId; orders.OrderDate = DateTime.Now; orders.DeliveryDate = DateTime.Now.AddDays(7); for (int i = 0; i < finalOrder.products.Count; i++) { sum += finalOrder.products[i].Quantity * finalOrder.products[i].Price; } orders.TotalAmount = sum; context.Orders.Add(orders); context.SaveChanges(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ProductOrderDetails[] products = new ProductOrderDetails[finalOrder.products.Count]; for (int i = 0; i < finalOrder.products.Count; i++) { products[i] = new ProductOrderDetails() { OrderId = orders.OrderId, ProductId = finalOrder.products[i].ProductId, Price = finalOrder.products[i].Price, Quantity = finalOrder.products[i].Quantity }; } context.ProductOrderDetails.AddRange(products); Payment payment = new Payment(); payment.Method = finalOrder.PaymentMode; payment.OrderId = orders.OrderId; payment.PaymentDate = DateTime.Now; context.Payment.Add(payment); context.SaveChanges(); Customer customer = context.Customer.SingleOrDefault(c => c.CustomerId == finalOrder.CustomerId); customer.Orders = null; InvoiceDetails details = new InvoiceDetails(); details.customer = customer; details.InvoiceNo = payment.InvoiceNo; return(details); }
public bool UpdateProductOrderDetailsDAL(ProductOrderDetails updateorder) { bool orderUpdated = false; try { for (int i = 0; i < productorderList.Count; i++) { if (productorderList[i].ProductOrderID == updateorder.ProductOrderID) { productorderList[i] = updateorder; } } } catch (Exception ex) { throw new InventoryException(ex.Message); } return(orderUpdated); }
public int UpdateQuantity(ReorderLevelDetails[] r) { int Quantity = 0; ProductOrderDetails[] ary = new ProductOrderDetails[r.Length]; foreach (var i in r) { Quantity += i.Quantity; } ProductOrder o = new ProductOrder() { ProductOrderDate = DateTime.Now, ProductOrderQuantity = Quantity, }; if (o.ProductOrderQuantity != 0) { context.ProductOrder.Add(o); context.SaveChanges(); } for (int j = 0; j < r.Length; j++) { ary[j] = new ProductOrderDetails() { ProductOrderQuantity = r[j].Quantity, BookId = r[j].BookId, RequestId = o.RequestId }; if (ary[j].ProductOrderQuantity != 0) { context.ProductOrderDetails.AddRange(ary[j]); context.SaveChanges(); } } return(o.RequestId); }