Beispiel #1
0
        public bool PlaceOrder(Order order, int customerId)
        {
            try
            {
                var orderAmount    = orderAmountFactory.GetOrderAmount(order.Amount);
                var orderValidator = orderAmountValidator.ValidateOrderAmount(orderAmount);

                if (orderValidator == false) // order amount is not valid
                {
                    return(false);
                }

                Customer customer = CustomerRepository.Load(customerId, configurations);

                if (customer == null)
                {
                    return(false);
                }

                var vatRate = vatService.GetVatRate(customer.Country);

                order.VAT        = vatRate;
                order.CustomerId = customerId;
                var success = orderRepository.Save(order, configurations);

                return(success);
            }
            catch (Exception ex)
            {
                // log error here
                return(false);
            }
        }
Beispiel #2
0
        public CustomerOrder GetOrder(int customerId)
        {
            try
            {
                if (customerId <= 0)
                {
                    return(null);
                }

                var customer = CustomerRepository.Load(customerId, configurations);

                if (customer == null)
                {
                    return(null);
                }

                var orders = orderRepository.GetOrders(customerId, configurations);

                var customerOrder = new CustomerOrder
                {
                    Customer = customer
                };
                customerOrder.Orders.AddRange(orders);

                return(customerOrder);
            }
            catch (Exception ex)
            {
                // log error here
                return(null);
            }
        }
        public bool PlaceOrder(Order order, int customerId)
        {
            try
            {
                Customer customer = CustomerRepository.Load(customerId);

                if (order.Amount == 0)
                {
                    return(false);
                }

                if (customer.Country.Equals(AnyCompanyHelpers.CountryNames.UK))
                {
                    order.VAT = 0.2d;
                }
                else
                {
                    order.VAT = 0;
                }

                orderRepository.Save(order);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Beispiel #4
0
        public bool PlaceOrder(Order order, int customerId)
        {
            Customer customer = CustomerRepository.Load(customerId);

            if (customer == null)
            {
                throw new CustomerNotFoundException("Customer with Id " + customerId + " Not Found");
            }
            if (order.Amount == 0)
            {
                return(false);
            }

            if (customer.Country == "UK")
            {
                order.VAT = 0.2d;
            }
            else
            {
                order.VAT = 0;
            }

            //Create a new order ref, this case a Guid should do even though its not ideal
            order.OrderNo = Guid.NewGuid().ToString();
            return(orderRepository.Save(order));;
        }
Beispiel #5
0
        public Customer GetCustomerWithOrder(int customerId)
        {
            var customer = CustomerRepository.Load(customerId);

            customer.Orders = orderRepository.GetOrdersForCustomer(customerId);

            return(customer);
        }
Beispiel #6
0
        public void PlaceOrder(Order order, int customerId)
        {
            if (order.Amount == 0)
            {
                throw new ArgumentException("Order Amount cannot be zero.", nameof(order));
            }

            var customer = CustomerRepository.Load(customerId);

            order.VAT = customer.Country == "UK" ? 0.2d : 0;

            orderRepository.Save(order, customer);
        }
Beispiel #7
0
        public bool PlaceOrder(IOrder order, Guid customerId)
        {
            var customer = CustomerRepository.Load(customerId);

            if (order.Amount < 0.0)
            {
                return(false);
            }

            order.VAT = customer.Country == "UK" ? Properties.Settings.Default.ukVat : Properties.Settings.Default.otherVat;

            order.CustomerId = customerId;
            orderRepository.Save(order);

            return(true);
        }
Beispiel #8
0
        public bool PlaceOrder(Order order, int customerId)
        {
            Customer customer = null;

            try
            {
                if (order == null || customerId <= 0)
                {
                    return(false);
                }

                customer = CustomerRepository.Load(customerId);

                if (customer == null)
                {
                    return(false);
                }

                if (order.Amount == 0)
                {
                    return(false);
                }

                if (customer.Country == "UK")
                {
                    order.VAT = 0.2d;
                }
                else
                {
                    order.VAT = 0;
                }

                order.CustomerId = customer.CustomerId;

                return(orderRepository.Save(order));
            }
            catch (System.Exception ex)
            {
                //Write log here
                throw;
            }
            finally
            {
                customer = null;
            }
        }
Beispiel #9
0
        public bool PlaceOrder(Order order)
        {
            try
            {
                Customer customer = CustomerRepository.Load(order.CustomerId);

                if (customer != null)
                {
                    order.CustomerId = customer.CustomerId;

                    if (order.Amount == 0)
                    {
                        return(false);
                    }

                    if (customer.Country == "UK")
                    {
                        order.VAT = 0.2d;
                    }
                    else
                    {
                        order.VAT = 0;
                    }

                    order = OrderRepository.Save(order);

                    return(order?.OrderId > 0);
                }
                else
                {
                    //To-do: Implement proper error logging
                    Console.WriteLine("Error : Customer doesn't exist");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                //To-do: Implement proper error logging
                Console.WriteLine("Error : " + ex.Message);
                return(false);
            }
        }
Beispiel #10
0
        public bool PlaceOrder(Order order, int customerId)
        {
            if (order == null)
            {
                throw new ArgumentNullException();
            }

            try
            {
                Customer customer = CustomerRepository.Load(customerId);

                if (order.Amount == 0)
                {
                    return(false);
                }

                if (customer == null)
                {
                    return(false);
                }

                switch (customer.Country)
                {
                case "UK":
                    order.VAT = 0.2d;
                    break;

                default:
                    order.VAT = 0;
                    break;
                }

                orderRepository.Save(order, customerId);

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception($"Failed to save order for customer with customer ID {customerId}", ex);
            }
        }
Beispiel #11
0
        public bool PlaceOrder(Order order, int customerId)
        {
            Customer customer = CustomerRepository.Load(customerId);

            if (order.Amount == 0)
            {
                return(false);
            }

            if (customer.Country == "UK")
            {
                order.VAT = 0.2d;
            }
            else
            {
                order.VAT = 0;
            }

            orderRepository.Save(order);

            return(true);
        }
Beispiel #12
0
        public bool PlaceOrder(Order order, int customerId)
        {
            try
            {
                Customer customer = CustomerRepository.Load(customerId);
                if (customer != null)
                {
                    order.CustomerId = customerId;
                    if (order.Amount == 0)
                    {
                        return(false);
                    }

                    if (customer.Country == "UK")
                    {
                        order.VAT = 0.2d;
                    }
                    else
                    {
                        order.VAT = 0;
                    }

                    orderRepository.Save(order);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Utils.LogErrorToDB(ex, "OrderService.PlaceOrder");
                return(false);
            }
        }
Beispiel #13
0
        public bool PlaceOrder(Order order, int customerId)
        {
            //verify the input
            if (order.Amount == 0)
            {
                return(false);
            }

            //apply business logic, based on the customer
            Customer customer;

            try
            {
                customer = CustomerRepository.Load(customerId, _customerDb);
            }
            catch (Exception exp)
            {
                //log
                return(false); // problem loading customer
            }

            if (customer.Country == "UK")
            {
                order.VAT = 0.2d;
            }
            else
            {
                order.VAT = 0;
            }

            order.CustomerId = customerId;

            _orderRepository.Save(order);

            return(true);
        }
 Customer ICustomerRepository.GetCustomer(int customerId)
 {
     return(CustomerRepository.Load(customerId));
 }
Beispiel #15
0
 public Customer GetCustomerFromId(int customerId)
 {
     return(CustomerRepository.Load(customerId));
 }