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 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); }
/// <summary> /// Create Customer /// </summary> /// <param name="customer"></param> public void CreateCustomer(Customer customer) { DateTime dateCreated = System.DateTime.Now; customer.CustomerID = Guid.NewGuid(); customer.DateCreated = dateCreated; customer.DateUpdated = dateCreated; Customers.Add(customer); }
public void TestValidEmailAddress() { Customer customer = new Customer(); customer.EmailAddress = "*****@*****.**"; ValidationRules validationRules = new ValidationRules(); validationRules.InitializeValidationRules(customer); Boolean returnStatus = validationRules.ValidateEmailAddress("EmailAddress"); Assert.AreEqual(true, returnStatus); }
/// <summary> /// Validate Customer /// </summary> /// <param name="customer"></param> /// <param name="dataService"></param> public void ValidateCustomer(Customer customer, ICustomerDataService dataService) { customerDataService = dataService; InitializeValidationRules(customer); ValidateRequired("FirstName", "First Name"); ValidateRequired("LastName", "Last Name"); ValidateRequired("EmailAddress", "Email Address"); ValidateEmailAddress("EmailAddress", "Email Address"); ValidateCreditInformation(customer); }
/// <summary> /// Validate Credit Information /// </summary> /// <param name="customer"></param> public void ValidateCreditInformation(Customer customer) { if (ValidateGuidRequired("PaymentTypeID", "Payment Type", "PaymentTypeID") == false) return; PaymentType paymentType = customerDataService.GetPaymentType(customer.PaymentTypeID); if (paymentType.RequiresCreditCard == (int)RequiresCreditCard.Yes) { ValidateRequired("CreditCardNumber", "For selected payment type, Credit Card Number"); ValidateNumeric("CreditCardNumber", "For selected payment type, Credit Card Number"); ValidateRequired("CreditCardSecurityCode", "For selected payment type, Credit Card Security Code"); ValidateNumeric("CreditCardSecurityCode", "For selected payment type, Credit Card Security Code"); ValidateRequiredDate("CreditCardExpirationDate", "For selected payment type, Credit Card Expiration Date"); } else { ValidateDecimalIsNotZero("CreditLimit", "For selected payment type, Credit Limit"); } }
/// <summary> /// Create Customer /// </summary> /// <param name="customer"></param> /// <param name="transaction"></param> public void CreateCustomer(Customer customer, out TransactionalInformation transaction) { transaction = new TransactionalInformation(); CustomerBusinessRules customerBusinessRules = new CustomerBusinessRules(); try { CustomerDataService.CreateSession(); customerBusinessRules.ValidateCustomer(customer, CustomerDataService); if (customerBusinessRules.ValidationStatus == true) { CustomerDataService.BeginTransaction(); CustomerDataService.CreateCustomer(customer); CustomerDataService.CommitTransaction(true); transaction.ReturnStatus = true; transaction.ReturnMessage.Add("Customer successfully created at " + customer.DateCreated.ToString()); } else { transaction.ReturnStatus = customerBusinessRules.ValidationStatus; transaction.ReturnMessage = customerBusinessRules.ValidationMessage; transaction.ValidationErrors = customerBusinessRules.ValidationErrors; } } catch (Exception ex) { CustomerDataService.RollbackTransaction(true); transaction.ReturnMessage = new List<string>(); string errorMessage = ex.Message; transaction.ReturnStatus = false; transaction.ReturnMessage.Add(errorMessage); } finally { CustomerDataService.CloseSession(); } }
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 CustomerMaintenanceViewModel() { Customer = new Customer(); PaymentTypes = new List<PaymentType>(); }
/// <summary> /// Update Customer /// </summary> /// <param name="customer"></param> public void UpdateCustomer(Customer customer) { DateTime dateUpdated = System.DateTime.Now; customer.DateUpdated = dateUpdated; }
/// <summary> /// Update Customer /// </summary> /// <param name="customer"></param> public void UpdateCustomer(Customer customer) { DateTime dateUpdated = System.DateTime.Now; customer.DateUpdated = dateUpdated; SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = dbConnection; sqlCommand.Transaction = dbTransaction; StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("UPDATE CUSTOMERS SET FirstName=@FirstName, LastName=@LastName, EmailAddress=@EmailAddress,"); sqlBuilder.Append(" Address=@Address, City=@City, Region=@Region, PostalCode=@PostalCode, Country=@Country, PhoneNumber=@PhoneNumber, CreditCardNumber=@CreditCardNumber,"); sqlBuilder.Append(" PaymentTypeID=@PaymentTypeID, CreditCardExpirationDate=@CreditCardExpirationDate, CreditCardSecurityCode=@CreditCardSecurityCode, CreditLimit=@CreditLimit,"); sqlBuilder.Append(" ApprovalStatus=@ApprovalStatus, DateCreated=@DateCreated, DateUpdated=@DateUpdated "); sqlBuilder.Append(" WHERE CustomerID = @CustomerID"); sqlCommand.CommandText = sqlBuilder.ToString(); sqlCommand.Parameters.Add("@CustomerID", System.Data.SqlDbType.UniqueIdentifier); sqlCommand.Parameters.Add("@FirstName", System.Data.SqlDbType.VarChar); sqlCommand.Parameters.Add("@LastName", System.Data.SqlDbType.VarChar); sqlCommand.Parameters.Add("@EmailAddress", System.Data.SqlDbType.VarChar); sqlCommand.Parameters.Add("@Address", System.Data.SqlDbType.VarChar); sqlCommand.Parameters.Add("@City", System.Data.SqlDbType.VarChar); sqlCommand.Parameters.Add("@Region", System.Data.SqlDbType.VarChar); sqlCommand.Parameters.Add("@PostalCode", System.Data.SqlDbType.VarChar); sqlCommand.Parameters.Add("@Country", System.Data.SqlDbType.VarChar); sqlCommand.Parameters.Add("@PhoneNumber", System.Data.SqlDbType.VarChar); sqlCommand.Parameters.Add("@CreditCardNumber", System.Data.SqlDbType.VarChar); sqlCommand.Parameters.Add("@PaymentTypeID", System.Data.SqlDbType.UniqueIdentifier); sqlCommand.Parameters.Add("@CreditCardExpirationDate", System.Data.SqlDbType.VarChar); sqlCommand.Parameters.Add("@CreditCardSecurityCode", System.Data.SqlDbType.VarChar); sqlCommand.Parameters.Add("@CreditLimit", System.Data.SqlDbType.Decimal); sqlCommand.Parameters.Add("@ApprovalStatus", System.Data.SqlDbType.Int); sqlCommand.Parameters.Add("@DateCreated", System.Data.SqlDbType.DateTime2); sqlCommand.Parameters.Add("@DateUpdated", System.Data.SqlDbType.DateTime2); sqlCommand.Parameters["@CustomerID"].Value = customer.CustomerID; sqlCommand.Parameters["@FirstName"].Value = Utilities.GetString(customer.FirstName); sqlCommand.Parameters["@LastName"].Value = Utilities.GetString(customer.LastName); sqlCommand.Parameters["@EmailAddress"].Value = Utilities.GetString(customer.EmailAddress); sqlCommand.Parameters["@Address"].Value = Utilities.GetString(customer.Address); sqlCommand.Parameters["@City"].Value = Utilities.GetString(customer.City); sqlCommand.Parameters["@Region"].Value = Utilities.GetString(customer.Region); sqlCommand.Parameters["@PostalCode"].Value = Utilities.GetString(customer.PostalCode); sqlCommand.Parameters["@Country"].Value = Utilities.GetString(customer.Country); sqlCommand.Parameters["@PhoneNumber"].Value = Utilities.GetString(customer.PhoneNumber); sqlCommand.Parameters["@CreditCardNumber"].Value = Utilities.GetString(customer.CreditCardNumber); sqlCommand.Parameters["@PaymentTypeID"].Value = customer.PaymentTypeID; if (customer.CreditCardExpirationDate != DateTime.MinValue && customer.CreditCardExpirationDate != null) sqlCommand.Parameters["@CreditCardExpirationDate"].Value = customer.CreditCardExpirationDate; else sqlCommand.Parameters["@CreditCardExpirationDate"].Value = DBNull.Value; sqlCommand.Parameters["@CreditCardSecurityCode"].Value = Utilities.GetString(customer.CreditCardSecurityCode); sqlCommand.Parameters["@CreditLimit"].Value = customer.CreditLimit; sqlCommand.Parameters["@ApprovalStatus"].Value = customer.ApprovalStatus; sqlCommand.Parameters["@DateCreated"].Value = customer.DateCreated; sqlCommand.Parameters["@DateUpdated"].Value = customer.DateUpdated; sqlCommand.ExecuteNonQuery(); }
/// <summary> /// Get Customer By Customer ID /// </summary> /// <param name="customerID"></param> /// <returns></returns> public Customer GetCustomerByCustomerID(Guid customerID) { Customer customer = new Customer(); string sql = "SELECT * FROM CUSTOMERS WHERE CustomerID = '" + customerID.ToString() + "'"; SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = dbConnection; sqlCommand.CommandText = sql; SqlDataReader reader = sqlCommand.ExecuteReader(); if (reader.Read()) { DataReader dataReader = new DataReader(reader); customer.CustomerID = dataReader.GetGuid("CustomerID"); customer.FirstName = dataReader.GetString("FirstName"); customer.LastName = dataReader.GetString("LastName"); customer.EmailAddress = dataReader.GetString("EmailAddress"); customer.Address = dataReader.GetString("Address"); customer.City = dataReader.GetString("City"); customer.Region = dataReader.GetString("Region"); customer.PostalCode = dataReader.GetString("PostalCode"); customer.Country = dataReader.GetString("Country"); customer.PhoneNumber = dataReader.GetString("PhoneNumber"); customer.CreditCardNumber = dataReader.GetString("CreditCardNumber"); customer.PaymentTypeID = dataReader.GetGuid("PaymentTypeID"); if (dataReader.GetDateTime("CreditCardExpirationDate") != DateTime.MinValue) customer.CreditCardExpirationDate = dataReader.GetDateTime("CreditCardExpirationDate"); customer.CreditCardSecurityCode = dataReader.GetString("CreditCardSecurityCode"); customer.CreditLimit = dataReader.GetDecimal("CreditLimit"); customer.DateApproved = dataReader.GetDateTime("DateApproved"); customer.ApprovalStatus = dataReader.GetInt32("ApprovalStatus"); customer.DateCreated = dataReader.GetDateTime("DateCreated"); customer.DateUpdated = dataReader.GetDateTime("DateUpdated"); } reader.Close(); return customer; }
public List<Customer> LoadDataSet(out TransactionalInformation transaction) { transaction = new TransactionalInformation(); Customers = new List<Customer>(); PaymentTypes = new List<PaymentType>(); try { PaymentType paymentType1 = new PaymentType(); paymentType1.PaymentTypeID = new Guid("dd000829-46dd-41a1-9d8d-5f55c3b844a1"); paymentType1.Description = "Check"; paymentType1.RequiresCreditCard = 0; PaymentTypes.Add(paymentType1); PaymentType paymentType2 = new PaymentType(); paymentType2.PaymentTypeID = new Guid("73db4cab-1ddb-466d-930f-97699373b333"); paymentType2.Description = "Visa"; paymentType2.RequiresCreditCard = 1; PaymentTypes.Add(paymentType2); PaymentType paymentType3 = new PaymentType(); paymentType3.PaymentTypeID = new Guid("3e0dd131-a8d3-4bfb-bded-9f7209b6965b"); paymentType3.Description = "American Express"; paymentType3.RequiresCreditCard = 1; PaymentTypes.Add(paymentType3); PaymentType paymentType4 = new PaymentType(); paymentType4.PaymentTypeID = new Guid("afb8207c-1f28-41e1-8834-e9a0041806a0"); paymentType4.Description = "Bill-Me Later"; paymentType4.RequiresCreditCard = 0; PaymentTypes.Add(paymentType4); PaymentType paymentType5 = new PaymentType(); paymentType5.PaymentTypeID = new Guid("1bcf2c92-028f-4664-9f5e-f39545691ce7"); paymentType5.Description = "Discover"; paymentType5.RequiresCreditCard = 1; PaymentTypes.Add(paymentType5); PaymentType paymentType6 = new PaymentType(); paymentType6.PaymentTypeID = new Guid("18851120-73c5-40f7-b498-f82aa7b28d24"); paymentType6.Description = "MasterCard"; paymentType6.RequiresCreditCard = 1; PaymentTypes.Add(paymentType6); DataSet dataSet = new DataSet(); dataSet.ReadXml(@"c:\myfiles\CodeProjectMVC5\TestData.xml"); int count = dataSet.Tables.Count; int rows = dataSet.Tables[0].Rows.Count; int paymentType = 0; int counter = 0; //DataSet cloneSet = dataSet.Clone(); //int colCount = dataSet.Tables[0].Columns.Count; for (int i = 0; i < dataSet.Tables[0].Rows.Count - 1; i++) { counter++; Customer customer = new Customer(); DataRow datarow = dataSet.Tables[0].Rows[i]; customer.CustomerID = Guid.NewGuid(); customer.FirstName = datarow["FirstName"].ToString(); customer.LastName = datarow["LastName"].ToString(); customer.PhoneNumber = datarow["PhoneNumber"].ToString(); customer.Address = datarow["AddressLine1"].ToString(); if ( datarow["AddressLine1"].ToString().Length>0) customer.Address = customer.Address + ", " + datarow["AddressLine2"].ToString(); customer.City = datarow["City"].ToString(); customer.Region = datarow["State"].ToString(); customer.PostalCode = datarow["ZipCode"].ToString(); customer.EmailAddress = datarow["EmailAddress"].ToString(); if (customer.EmailAddress.Trim().Length==0) { customer.EmailAddress = customer.LastName + customer.FirstName + "@hotmail.com"; } customer.EmailAddress = customer.EmailAddress.Replace(" ", ""); customer.CreditLimit = 0; customer.CreditCardNumber = ""; customer.CreditCardSecurityCode = ""; customer.DateCreated = DateTime.Now; customer.DateUpdated = DateTime.Now; DateTime birthDate; DateTime testDate; DateTime creditCardExpirationDate; string dob = Convert.ToString(datarow["DateOfBirth"]); if (DateTime.TryParse(dob,out testDate)) { birthDate = testDate; string year = birthDate.Year.ToString(); string creditCardDate = birthDate.Month + "/" + birthDate.Day + "/" + year; creditCardExpirationDate = Convert.ToDateTime(creditCardDate); } else { creditCardExpirationDate = Convert.ToDateTime(DateTime.Now.AddYears(1)); } paymentType = paymentType + 1; int requiresCreditCard = 0; if (paymentType == 1) { customer.PaymentTypeID = paymentType1.PaymentTypeID; requiresCreditCard = paymentType1.RequiresCreditCard; } else if (paymentType == 2) { customer.PaymentTypeID = paymentType2.PaymentTypeID; requiresCreditCard = paymentType2.RequiresCreditCard; } else if (paymentType == 3) { customer.PaymentTypeID = paymentType3.PaymentTypeID; requiresCreditCard = paymentType3.RequiresCreditCard; } else if (paymentType == 4) { customer.PaymentTypeID = paymentType4.PaymentTypeID; requiresCreditCard = paymentType4.RequiresCreditCard; } else if (paymentType == 5) { customer.PaymentTypeID = paymentType5.PaymentTypeID; requiresCreditCard = paymentType5.RequiresCreditCard; } else if (paymentType == 6) { customer.PaymentTypeID = paymentType6.PaymentTypeID; requiresCreditCard = paymentType6.RequiresCreditCard; paymentType = 0; } if (requiresCreditCard==0) { Random random = new Random(); int creditLimit = random.Next(1000, 10000); customer.CreditLimit = (Decimal)creditLimit; } else { Random random = new Random(); int creditCardNumber = random.Next(1000000, 14000000); int creditCardSecurityCode = random.Next(100, 999); customer.CreditCardNumber = creditCardNumber.ToString(); customer.CreditCardSecurityCode = creditCardSecurityCode.ToString(); customer.CreditCardExpirationDate = creditCardExpirationDate; } //if (counter == 50) //{ //DataRow workRow = cloneSet.Tables[0].NewRow(); //for (int x = 0; x < colCount; x++) //{ // workRow[x] = datarow[x]; //} //cloneSet.Tables[0].Rows.Add(workRow); //Customers.Add(customer); //counter = 0; //} Customers.Add(customer); } transaction.ReturnMessage = new List<string>(); transaction.ReturnStatus = true; transaction.ReturnMessage.Add("Records Loaded = " + rows.ToString()); //int clonedrows = cloneSet.Tables[0].Rows.Count; //cloneSet.WriteXml(@"c:\myfiles\CodeProjectMVC5\TestData.xml"); return Customers; } catch (Exception ex) { transaction.ReturnMessage = new List<string>(); string errorMessage = ex.Message; transaction.ReturnStatus = false; transaction.ReturnMessage.Add(errorMessage); return null; } }
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); }
/// <summary> /// Populate Customer Information /// </summary> /// <param name="customer"></param> /// <param name="originalCustomerInformation"></param> private void PopulateCustomerInformation(Customer customer, Customer originalCustomerInformation) { originalCustomerInformation.FirstName = customer.FirstName; originalCustomerInformation.LastName = customer.LastName; originalCustomerInformation.CreditCardNumber = customer.CreditCardNumber; originalCustomerInformation.CreditCardSecurityCode = customer.CreditCardSecurityCode; originalCustomerInformation.CreditLimit = customer.CreditLimit; originalCustomerInformation.Address = customer.Address; originalCustomerInformation.City = customer.City; originalCustomerInformation.Country = customer.Country; originalCustomerInformation.PhoneNumber = customer.PhoneNumber; originalCustomerInformation.PostalCode = customer.PostalCode; originalCustomerInformation.Region = customer.Region; originalCustomerInformation.EmailAddress = customer.EmailAddress; originalCustomerInformation.PaymentTypeID = customer.PaymentTypeID; }
/// <summary> /// Initialize Customer Business Rules /// </summary> /// <param name="customer"></param> /// <param name="dataService"></param> public void InitializeCustomerBusinessRules(Customer customer, ICustomerDataService dataService) { customerDataService = dataService; InitializeValidationRules(customer); }