public bool AddNewOrder(AddOrderOptions options) { if (options == null) { return(false); } if (options.Id == null) { return(false); } if (options.Products == null) { return(false); } var customerService = new CustomerService(); var customer = customerService.GetCustomerById(options.Id); if (customer == null) { Console.WriteLine("No customer with such id"); return(false); } if (customer.Status == false) { Console.WriteLine("the customer is inactive"); return(false); } var productService = new ProductService(); foreach (var p in options.Products) { var product = productService.GetProductById(p.Id); if (product == null) { Console.WriteLine($" The product with id {p.Id} does not exist "); return(false); } } var newOrder = new Order(); newOrder.Id = options.Id; newOrder.Products = new List <Product>(options.Products); newOrder.OrderStatus = true; OrderList.Add(newOrder); GetOrderDetails(newOrder); return(true); }
public Order AddOrder(string custId, AddOrderOptions options) { if (options == null) { return(null); } if (string.IsNullOrWhiteSpace(custId)) { return(null); } var customer = customerService.GetCustomerById(options.CustomerId); if (customer == null) { return(null); } if (string.IsNullOrWhiteSpace(options.DeliveryAddress)) { return(null); } if (options.OrderProductList.Count <= 0) { return(null); } foreach (var p in options.OrderProductList) { if (prodService.GetProductById(p.Id) == null) { return(null); } } if (!customer.Status.Equals(true)) { return(null); } var order = new Order() { DeliveryAddress = options.DeliveryAddress, OrderProductList = options.OrderProductList, CustomerId = options.CustomerId, OrderId = Convert.ToString(counter_ + 1), OrderStatus = OrderStatus.Pending, TotalMount = GetTotalAmount(options.OrderProductList) }; OrdersList.Add(order); return(order); }
public bool UpdateOrder(string orderId, UpdateOrderOptions options) { if (options == null) { return(false); } if (string.IsNullOrWhiteSpace(orderId)) { return(false); } var order = FindOrderById(orderId); if (order == null) { return(false); } if (order.OrderStatus == OrderStatus.Execute) { return(false); } if (options.TobeCancel == false) { return(false); } var custom = customerService.GetCustomerById(order.CustomerId); if (order.OrderStatus == OrderStatus.Pending && options.TobeCancel == true) { order.OrderStatus = OrderStatus.Cansel; Console.WriteLine("press 1 for cancel order or 2 for cancel and add new order "); var x = int.Parse(Console.ReadLine()); if (x == 1) { OrdersList.Remove(order); } else if (x == 2) { OrdersList.Remove(order); var opt = new AddOrderOptions() { }; OrdersList.Add( AddOrder(custom.CustomerId, opt)); } } return(true); }