public void CreateCustomerIntegrationTest()
        {
            string returnMessage;

            TransactionalInformation transaction;

            CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService);
            List<PaymentType> paymentTypes = customerApplicationService.GetPaymentTypes(out transaction);

            var paymentType = (from p in paymentTypes where p.Description == "Visa" select p).First();

            Customer customer = new Customer();
            customer.FirstName = "William";
            customer.LastName = "Gates";
            customer.EmailAddress = "*****@*****.**";
            customer.PhoneNumber = "(425)882-8080";
            customer.Address = "One Microsoft Way";
            customer.City = "Redmond";
            customer.Region = "WA";
            customer.PostalCode = "98052-7329";
            customer.PaymentTypeID = paymentType.PaymentTypeID;
            customer.CreditCardExpirationDate = Convert.ToDateTime("12/31/2014");
            customer.CreditCardSecurityCode = "111";
            customer.CreditCardNumber = "123111234";

            customerApplicationService.CreateCustomer(customer, out transaction);

            returnMessage = Utilities.GetReturnMessage(transaction.ReturnMessage);

            Assert.AreEqual(true, transaction.ReturnStatus,returnMessage);
        }
        public void ValidateCustomerWithCheckPayment()
        {
            TransactionalInformation transaction;

            CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService);
            List<PaymentType> paymentTypes = customerApplicationService.GetPaymentTypes(out transaction);

            var paymentType = (from p in paymentTypes where p.Description == "Check" select p).First();

            Customer customer = new Customer();
            customer.FirstName = "Bill";
            customer.LastName = "Gates";
            customer.EmailAddress = "*****@*****.**";
            customer.PaymentTypeID = paymentType.PaymentTypeID;
            customer.CreditLimit = 1000.00m;

            customerDataService.CreateSession();
            CustomerBusinessRules customerBusinessRules = new CustomerBusinessRules();
            customerBusinessRules.ValidateCustomer(customer, customerDataService);
            customerDataService.CloseSession();

            string returnMessage = Utilities.GetReturnMessage(customerBusinessRules.ValidationMessage);

            Assert.AreEqual(true, customerBusinessRules.ValidationStatus, returnMessage);
        }
        public HttpResponseMessage SeedData(HttpRequestMessage request)
        {
            TransactionalInformation transaction;

            SeedDataViewModel seedDataViewModel = new SeedDataViewModel();

            SeedData seedData = new SeedData();
            List<Customer> customers = seedData.LoadDataSet(out transaction);
            if (transaction.ReturnStatus==false)
            {
                seedDataViewModel.ReturnStatus = false;
                seedDataViewModel.ReturnMessage = transaction.ReturnMessage;
                var badresponse = Request.CreateResponse<SeedDataViewModel>(HttpStatusCode.BadRequest, seedDataViewModel);
                return badresponse;
            }

            long startTickCount = System.Environment.TickCount;

            CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService);
            customerApplicationService.DeleteAllCustomers(out transaction);
            if (transaction.ReturnStatus==false)
            {
                seedDataViewModel.ReturnStatus = false;
                seedDataViewModel.ReturnMessage = transaction.ReturnMessage;
                var badresponse = Request.CreateResponse<SeedDataViewModel>(HttpStatusCode.BadRequest, seedDataViewModel);
                return badresponse;
            }

            foreach (Customer customer in customers)
            {
                customerApplicationService.CreateCustomer(customer, out transaction);
                if (transaction.ReturnStatus==false)
                {
                    transaction.ReturnMessage.Add("for " + customer.LastName + "," + customer.FirstName);
                    seedDataViewModel.ReturnStatus = false;
                    seedDataViewModel.ReturnMessage = transaction.ReturnMessage;
                    var badresponse = Request.CreateResponse<SeedDataViewModel>(HttpStatusCode.BadRequest, seedDataViewModel);
                    return badresponse;
                }
            }

            long endTickCount = System.Environment.TickCount;
            decimal ticks = ((endTickCount - startTickCount)/1000)/60;

            List<String> returnMessage = new List<String>();
            returnMessage.Add(customers.Count.ToString() + " customers created in " + ticks.ToString() + " minutes");

            seedDataViewModel.ReturnStatus = true;
            seedDataViewModel.ReturnMessage = returnMessage;

            var response = Request.CreateResponse<SeedDataViewModel>(HttpStatusCode.OK, seedDataViewModel);
            return response;
        }
        public void CustomerInquiryIntegrationTest()
        {
            TransactionalInformation transaction;

            CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService);

            DataGridPagingInformation paging = new DataGridPagingInformation();
            paging.CurrentPageNumber = 1;
            paging.PageSize = 15;
            paging.SortExpression = "LastName";
            paging.SortDirection = "ASC";

            List<CustomerInquiry> customers = customerApplicationService.CustomerInquiry("", "", paging, out transaction);

            string returnMessage = Utilities.GetReturnMessage(transaction.ReturnMessage);

            Assert.AreEqual(15, customers.Count, returnMessage);
        }
        public HttpResponseMessage CreateCustomer(HttpRequestMessage request, [FromBody] CustomerMaintenanceDTO customerDTO)
        {
            TransactionalInformation transaction;

            CustomerMaintenanceViewModel customerMaintenanceViewModel = new CustomerMaintenanceViewModel();

            if (!ModelState.IsValid)
            {
                var errors = ModelState.Errors();
                customerMaintenanceViewModel.ReturnMessage = ModelStateHelper.ReturnErrorMessages(errors);
                customerMaintenanceViewModel.ValidationErrors = ModelStateHelper.ReturnValidationErrors(errors);
                customerMaintenanceViewModel.ReturnStatus = false;
                var badresponse = Request.CreateResponse<CustomerMaintenanceViewModel>(HttpStatusCode.BadRequest, customerMaintenanceViewModel);
                return badresponse;
            }

            Customer customer = new Customer();

            ModelStateHelper.UpdateViewModel(customerDTO, customer);

            CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService);
            customerApplicationService.CreateCustomer(customer, out transaction);

            customerMaintenanceViewModel.Customer = customer;
            customerMaintenanceViewModel.ReturnStatus = transaction.ReturnStatus;
            customerMaintenanceViewModel.ReturnMessage = transaction.ReturnMessage;
            customerMaintenanceViewModel.ValidationErrors = transaction.ValidationErrors;

            if (transaction.ReturnStatus==false)
            {
                var badresponse = Request.CreateResponse<CustomerMaintenanceViewModel>(HttpStatusCode.BadRequest, customerMaintenanceViewModel);
                return badresponse;
            }
            else
            {
                var response = Request.CreateResponse<CustomerMaintenanceViewModel>(HttpStatusCode.Created, customerMaintenanceViewModel);
                return response;
            }
        }
        public HttpResponseMessage GetCustomerMaintenanceInformation(HttpRequestMessage request,Guid customerID)
        {
            TransactionalInformation customerTransaction;
            TransactionalInformation paymentTransaction;

            CustomerMaintenanceViewModel customerMaintenanceViewModel = new CustomerMaintenanceViewModel();

            CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService);

            if (customerID != Guid.Empty)
            {
                Customer customer = customerApplicationService.GetCustomerByCustomerID(customerID, out customerTransaction);
                customerMaintenanceViewModel.Customer = customer;
                customerMaintenanceViewModel.ReturnStatus = customerTransaction.ReturnStatus;
                customerMaintenanceViewModel.ReturnMessage = customerTransaction.ReturnMessage;
            }

            List<PaymentType> paymentTypes = customerApplicationService.GetPaymentTypes(out paymentTransaction);
            customerMaintenanceViewModel.PaymentTypes = paymentTypes;
            if (paymentTransaction.ReturnStatus==false)
            {
                customerMaintenanceViewModel.ReturnStatus = paymentTransaction.ReturnStatus;
                customerMaintenanceViewModel.ReturnMessage = paymentTransaction.ReturnMessage;
            }

            if (customerMaintenanceViewModel.ReturnStatus == true)
            {
                var response = Request.CreateResponse<CustomerMaintenanceViewModel>(HttpStatusCode.OK, customerMaintenanceViewModel);
                return response;
            }

            var badResponse = Request.CreateResponse<CustomerMaintenanceViewModel>(HttpStatusCode.BadRequest, customerMaintenanceViewModel);
            return badResponse;
        }
        public HttpResponseMessage CustomerInquiry(string FirstName, string LastName, int CurrentPageNumber, string SortExpression, string SortDirection, int PageSize)
        {
            TransactionalInformation transaction;

            if (FirstName == null) FirstName = string.Empty;
            if (LastName == null) LastName = string.Empty;
            if (SortDirection == null) SortDirection = string.Empty;
            if (SortExpression == null) SortExpression = string.Empty;

            CustomerInquiryViewModel customerInquiryViewModel = new CustomerInquiryViewModel();

            DataGridPagingInformation paging = new DataGridPagingInformation();
            paging.CurrentPageNumber = CurrentPageNumber;
            paging.PageSize = PageSize;
            paging.SortExpression = SortExpression;
            paging.SortDirection = SortDirection;

            if (paging.SortDirection == "") paging.SortDirection = "ASC";
            if (paging.SortExpression == "") paging.SortExpression = "LastName";

            CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService);
            List<CustomerInquiry> customers = customerApplicationService.CustomerInquiry(FirstName, LastName, paging, out transaction);

            customerInquiryViewModel.Customers = customers;
            customerInquiryViewModel.ReturnStatus = transaction.ReturnStatus;
            customerInquiryViewModel.ReturnMessage = transaction.ReturnMessage;
            customerInquiryViewModel.TotalPages = paging.TotalPages;
            customerInquiryViewModel.TotalRows = paging.TotalRows;
            customerInquiryViewModel.PageSize = paging.PageSize;

            if (transaction.ReturnStatus == true)
            {
                var response = Request.CreateResponse<CustomerInquiryViewModel>(HttpStatusCode.OK, customerInquiryViewModel);
                return response;
            }

            var badResponse = Request.CreateResponse<CustomerInquiryViewModel>(HttpStatusCode.BadRequest, customerInquiryViewModel);
            return badResponse;
        }
        public void UpdateCustomerIntegrationTest()
        {
            string returnMessage;

            TransactionalInformation transaction;

            CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService);

            DataGridPagingInformation paging = new DataGridPagingInformation();
            paging.CurrentPageNumber = 1;
            paging.PageSize = 15;
            paging.SortExpression = "LastName";
            paging.SortDirection = "ASC";

            List<CustomerInquiry> customers = customerApplicationService.CustomerInquiry("", "", paging, out transaction);

            var customerInformation = (from c in customers select c).First();
            Guid customerID = customerInformation.CustomerID;

            Customer customer = customerApplicationService.GetCustomerByCustomerID(customerID, out transaction);

            customerApplicationService.UpdateCustomer(customer, out transaction);
            returnMessage = Utilities.GetReturnMessage(transaction.ReturnMessage);

            Assert.AreEqual(true, transaction.ReturnStatus, returnMessage);
        }
        public void ValidateCustomerWithCreditCardPayment()
        {
            TransactionalInformation transaction;

            CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService);
            List<PaymentType> paymentTypes = customerApplicationService.GetPaymentTypes(out transaction);

            var paymentType = (from p in paymentTypes where p.Description == "Visa" select p).First();

            Customer customer = new Customer();
            customer.FirstName = "Bill";
            customer.LastName = "Gates";
            customer.EmailAddress = "*****@*****.**";
            customer.PaymentTypeID = paymentType.PaymentTypeID;
            customer.CreditCardNumber = "1112223333";
            customer.CreditCardExpirationDate = Convert.ToDateTime("12/31/2014");
            customer.CreditCardSecurityCode = "111";

            customerDataService.CreateSession();
            CustomerBusinessRules customerBusinessRules = new CustomerBusinessRules();
            customerBusinessRules.ValidateCustomer(customer, customerDataService);
            customerDataService.CloseSession();

            string returnMessage = Utilities.GetReturnMessage(customerBusinessRules.ValidationMessage);

            Assert.AreEqual(true, customerBusinessRules.ValidationStatus, returnMessage);
        }