Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        public bool PlaceOrder(Order order, int customerId)
        {
            try
            {
                using (OrderRepository orderRepository = new OrderRepository())
                {
                    Customer customer = GetCustomer(customerId);

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

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

                    orderRepository.Save(order);

                    return(true);
                }
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
Ejemplo n.º 3
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));;
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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;
            }
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
 public void SaveOrder(Order order, int customerId)
 {
     orderRepository.Save(order, customerId);
 }