public OperationsResult ValidateEmail()
        {
            OperationsResult operationsResult = new OperationsResult();

            if (string.IsNullOrWhiteSpace(this.EmailAddress))
            {
                operationsResult.Success = false;
                operationsResult.AddMessage("Email address is null");
            }

            if (operationsResult.Success)
            {
                var isValidFormat = true;
                // Code here that validates the format of the email
                // using regular expressions.
                if (!isValidFormat)
                {
                    operationsResult.Success = false;
                    operationsResult.AddMessage("Email address is not in a correct format");
                }
            }


            if (operationsResult.Success)
            {
                var isRealDomain = true;
                if (!isRealDomain)
                {
                    operationsResult.Success = false;
                    operationsResult.AddMessage("Email addres does not include a valid domain");
                }
            }

            return(operationsResult);
        }
Пример #2
0
        public OperationsResult PlaceOrder(Customer customer,
                                           Order order,
                                           Payment payment,
                                           bool allowSplitOrders,
                                           bool emailReciepts)
        {
            // Only works during the debug phase
            Debug.Assert(customerRepository != null, "Missing customer repository instance");
            Debug.Assert(orderRepository != null, "Missing order repository instance");
            Debug.Assert(inventoryRepository != null, "Missing inventory repository instance");
            Debug.Assert(emailLibrary != null, "Missing email repository instance");

            if (customer == null)
            {
                throw new ArgumentNullException("Customer instance is null");
            }
            if (order == null)
            {
                throw new ArgumentNullException("Order instance is null");
            }
            if (payment == null)
            {
                throw new ArgumentNullException("Payment instance is null");
            }

            var op = new OperationsResult();

            customerRepository.Add(customer);

            orderRepository.Add(order);

            inventoryRepository.OrderItems(order, allowSplitOrders);

            payment.ProcessPayment(payment);

            if (emailReciepts)
            {
                var result = customer.ValidateEmail();
                if (result.Success)
                {
                    customerRepository.Update();

                    emailLibrary.SendEmail(customer.EmailAddress, "reciept");
                }
                else
                {
                    //log the messages
                    if (result.MessageList.Any())
                    {
                        op.AddMessage(result.MessageList[0]);
                    }
                }
            }
            return(op);
        }