示例#1
0
        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);
        }
示例#2
0
        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);
        }