示例#1
0
        public ClassRegistration Get(long id)
        {
            MySqlCommand cmd = _unitOfWork.CreateCommand(@"select RegistrationId, RegistrationData, Created, Completed From Registrations Where RegistrationId = @RegistrationId",
                                                         System.Data.CommandType.Text);

            cmd.Parameters.AddWithValue("@RegistrationId", id);

            ClassRegistration registration = null;

            var contractResolver    = new PrivateMemberContractResolver();
            var deserializeSettings = new JsonSerializerSettings()
            {
                ContractResolver = contractResolver
            };

            using (MySqlDataReader r = cmd.ExecuteReader())
            {
                if (r.Read())
                {
                    registration = JsonConvert.DeserializeObject <ClassRegistration>(r.GetString(1), deserializeSettings);
                }
            }

            return(registration);
        }
示例#2
0
        public void RegisterWithInvalidPhoneNumber()
        {
            RegistrationRequest request = new RegistrationRequest()
            {
                Phone = "123"
            };

            ClassRegistration result = ClassRegistration.Process(request, new[] { new PhoneValidator() });

            Assert.AreEqual("A phone number is required", result.GetError("Phone"));
        }
示例#3
0
        public void RegisterWithPaymentAmountOutsideAllowableRange()
        {
            RegistrationRequest request = new RegistrationRequest()
            {
                PaymentAmount = "600"
            };

            ClassRegistration result = ClassRegistration.Process(request, new[] { new PaymentAmountValidator(5, 500) });

            Assert.AreEqual("Payment amount must be between $5 and $500", result.GetError("PaymentAmount"));
        }
示例#4
0
        public void RegisterWithOnlyFirstNameFilled()
        {
            RegistrationRequest request = new RegistrationRequest()
            {
                Name = "Shelly"
            };

            ClassRegistration result = ClassRegistration.Process(request, null);

            Assert.AreEqual("Shelly", result.FirstName);
        }
示例#5
0
        public void RegisterWithValidPaymentAmount()
        {
            RegistrationRequest request = new RegistrationRequest()
            {
                Name          = "Sweet Ride",
                PaymentAmount = "300"
            };

            ClassRegistration result = ClassRegistration.Process(request, new[] { new PaymentAmountValidator(5, 500) });

            Assert.AreEqual(300, result.PaymentAmount);
        }
示例#6
0
        public void RegisterWithFullName()
        {
            RegistrationRequest request = new RegistrationRequest()
            {
                Name = "Shelly Von Trapp"
            };

            ClassRegistration result = ClassRegistration.Process(request, null);

            Assert.AreEqual("Shelly", result.FirstName);
            Assert.AreEqual("Von Trapp", result.LastName);
        }
示例#7
0
        public void RegisterWithValidEmailAddress()
        {
            RegistrationRequest request = new RegistrationRequest()
            {
                Name  = "Joe",
                Email = "*****@*****.**"
            };

            ClassRegistration result = ClassRegistration.Process(request, new[] { new EmailValidator() });

            Assert.AreEqual("*****@*****.**", result.Email);
        }
示例#8
0
        public void RegisterWithInvalidEmailAddress()
        {
            RegistrationRequest request = new RegistrationRequest()
            {
                Name  = "Joe",
                Email = "Smith@ish"
            };

            ClassRegistration result = ClassRegistration.Process(request, new[] { new EmailValidator() });

            Assert.AreEqual("A valid email address is required", result.GetError("Email"));
        }
示例#9
0
        public void RegisterWithNameMissing()
        {
            RegistrationRequest request = new RegistrationRequest()
            {
                Name = null,
            };

            ClassRegistration result = ClassRegistration.Process(request, null);

            Assert.IsFalse(result.IsValid);

            Assert.AreEqual("Name is required", result.GetError("Name"));
        }
示例#10
0
        public void Save(ClassRegistration registration)
        {
            MySqlCommand cmd = _unitOfWork.CreateCommand(@"insert into Registrations(RegistrationId, RegistrationData, Created, Completed)
                Values(@RegistrationId, @RegistrationData, @Created, @Completed)",
                                                         System.Data.CommandType.Text);


            cmd.Parameters.AddWithValue("@RegistrationId", registration.RegistrationId);
            cmd.Parameters.AddWithValue("@RegistrationData", Newtonsoft.Json.JsonConvert.SerializeObject(registration));
            cmd.Parameters.AddWithValue("@Created", registration.Created);
            cmd.Parameters.AddWithValue("@Completed", registration.Completed);

            cmd.ExecuteNonQuery();
        }
示例#11
0
        public void RegisterWithValidShortPhoneNumber()
        {
            RegistrationRequest request = new RegistrationRequest()
            {
                Name  = "Joe",
                Phone = "283-5266"
            };

            ClassRegistration result = ClassRegistration.Process(request, new[] { new PhoneValidator() });

            Assert.AreEqual("413", result.PhoneAreaCode);
            Assert.AreEqual("283", result.PhonePrefix);
            Assert.AreEqual("5266", result.PhoneSuffix);
        }
示例#12
0
        public void RegisterWithOptionalFieldsFilled()
        {
            RegistrationRequest request = new RegistrationRequest()
            {
                Name                = "Joe",
                Address             = "Address 1",
                Town                = "Townie",
                SpecialInstructions = "Environment needs to be quiet.",
                EventName           = "Event name",
                EventDescription    = "Event description"
            };

            ClassRegistration result = ClassRegistration.Process(request, new Validator <RegistrationRequest>[] { });

            Assert.AreEqual("Address 1", result.Address1);
            Assert.AreEqual("Townie", result.City);
            Assert.AreEqual("Environment needs to be quiet.", result.SpecialInstructions);
            Assert.AreEqual("Event name", result.EventName);
            Assert.AreEqual("Event description", result.EventDescription);
        }
        public void SaveCustomerRegistration()
        {
            ClassRegistrationRepository repo = new ClassRegistrationRepository(_unitOfWork);

            RegistrationRequest request = new RegistrationRequest()
            {
                Name = "Joe Smith",
                SpecialInstructions = "Really needy",
                EventDescription    = "Event Description"
            };

            var classRegistration = ClassRegistration.Process(request, new Validator <RegistrationRequest>[] { });

            repo.Save(classRegistration);

            ClassRegistration savedRegistration = repo.Get(classRegistration.RegistrationId);

            Assert.IsNotNull(savedRegistration.RegistrationId);
            Assert.AreEqual("Really needy", savedRegistration.SpecialInstructions);
            Assert.AreEqual("Event Description", savedRegistration.EventDescription);
        }
        // POST api/<controller>
        public IHttpActionResult Post([FromBody] RegistrationRequest request)
        {
            var validators = new Validator <RegistrationRequest>[]
            {
                new PaymentAmountValidator(decimal.Parse(ConfigurationManager.AppSettings["MinPaymentAmount"]),
                                           decimal.Parse(ConfigurationManager.AppSettings["MaxPaymentAmount"])),
                new PhoneValidator(),
                new EmailValidator()
            };

            ClassRegistration registration = ClassRegistration.Process(request, validators);

            if (registration.IsValid)
            {
                StringBuilder body = new StringBuilder();
                body.AppendFormat("<p>This e-mail is a notification that the class registration process has started.  This notification <strong>does not indicate</strong> that the customer has successfully completed payment process through PayPal.  The Registration ID and other contact information can be used to track payment status in PayPal.</p>");
                body.AppendFormat("<div>Registration ID: {0}</div>", registration.RegistrationId);
                body.AppendFormat("<div>Event: {0}</div>", registration.EventName);
                body.AppendFormat("<div>Name: {0}</div>", registration.FullName);
                body.AppendFormat("<div>Payment Amount: {0}</div>", registration.PaymentAmount);
                body.AppendFormat("<div>Address: {0}</div>", registration.Address1);
                body.AppendFormat("<div>Town: {0}</div>", registration.City);
                body.AppendFormat("<div>Phone: {0}</div>", registration.FormattedPhone);
                body.AppendFormat("<div>Email: {0}</div>", registration.Email);
                body.AppendFormat("<div>Special Instructions:</div><p>{0}</p>", registration.SpecialInstructions);

                SiteMessage siteMessage = new SiteMessage()
                {
                    From    = registration.Email,
                    To      = ConfigurationManager.AppSettings["ContactUsEmailAddress"],
                    Subject = "Class Registration: Interactive School House",
                    Body    = body.ToString()
                };

                SendGridMailAdapter sendGridMailAdapter = new SendGridMailAdapter();
                sendGridMailAdapter.Send(siteMessage);
            }

            return(Ok(registration));
        }
 public decimal ProcessRegistration(ClassRegistration classRegistration)
 {
     classRegistration.Create();
     return(classRegistration.Total);
 }
		public decimal ProcessRegistration(ClassRegistration registration)
		{
			registration.Create();
			return registration.Total;
		}