/// <summary> /// Add new EventRegistration to the database /// </summary> /// <param name="obj">EventRegistration object to be saved to the database</param> /// <returns>success or failure</returns> public ServiceResultEnum Create(ref RoughRiderRegistration obj) { var eventReg = obj.EventRegistration; // Number of changes as a result of the database change NumberChanges = 0; // remove blank attendees eventReg.Attendees.RemoveAll(a => string.IsNullOrEmpty(a.Person.FirstName)); eventReg.Attendees.ForEach(a => a.Person.Base.EmailAddresses.RemoveAll(b => string.IsNullOrEmpty(b.Address))); eventReg.Attendees.ForEach(a => a.Person.Base.PhoneNumbers.RemoveAll(b => string.IsNullOrEmpty(b.Number))); eventReg.Event = null; // only perform if payment section was shown to the user if (obj.ShowPaymentSection) { // send information to payment service var paymentResult = ServiceResultEnum.Failure; var payment = obj.GetPaymentInformation(); try { var brainTreeHandler = new BrainTreeHandler(); paymentResult = brainTreeHandler.SendTransactionRequest(ref payment); if (paymentResult == ServiceResultEnum.Success) { ServiceResult = paymentResult; eventReg.PaymentTransactionId = payment.TransactionResult.Target.Id; eventReg.HasPaid = true; Messages.Add("Payment processed successfully"); } } catch (Exception ex) { Messages.Add(ex.Message); } // check if the payment was not processed if (paymentResult == ServiceResultEnum.Failure) { Messages.Add(payment.TransactionResult.Message); var errorMessage = payment.ErrorMessage(); if (errorMessage.IsNotNullOrEmpty()) { Messages.Add(errorMessage); } ServiceResult = paymentResult; return(ServiceResult); } } // payment is a success, save information to the database try { // Perform data access using the context using (var context = new HuskyRescueEntities()) { // convert to database object var dbObj = eventReg.ToModel(); // add to the database and retrieve the updated object back (namely the GUID generated into the Id) dbObj = context.Event_Registration.Add(dbObj); // commit changes to the database NumberChanges = context.SaveChanges(); // convert the database object back to a presentation object with included changes from the database (if any) eventReg = dbObj.ToViewModel(); } } catch (InvalidOperationException ex) { Trace.WriteLine(ex.Message); Messages.Add(ex.Message); } catch (DbEntityValidationException ex) { Messages.AddRange(Common.FormatEntityValidationError(ex)); } // check if database changes were a success ServiceResult = NumberChanges > 0 ? ServiceResultEnum.Success : ServiceResultEnum.Failure; if (ServiceResult == ServiceResultEnum.Success) { Messages.Add("Registration saved to database successfully"); } // if the save to database didn't work then keep going as the payment already processed. // TODO: log registration information to database for manual entry // send emails var emailSendResult = ServiceResultEnum.Failure; try { const string subject = "2014 TXHR Night out with the Frisco RoughRiders"; const string bodyAppHtml = @" Thank You for supporting Texas Husky Rescue. Your tickets will be available at Will Call the night of the game. As a reminder, the game is Friday May 23 at 7:05 PM at the DrPepper Ballpark. For seating and directions see this site http://goo.gl/BujLRR. Advance parking passes can also be purchased from Jessica (972-334-1936 or [email protected]) with the RoughRiders for $5. Parking passes purchased the day of the game are $10. We'll see you at the game! Thank you, Texas Husky Rescue 1-877-TX-HUSKY (894-8759) (phone/fax) PO Box 118891, Carrollton, TX 75011 "; var message = new EmailMessage { BodyTextExternal = bodyAppHtml, BodyTextInternal = eventReg.RegistrationDescription, Subject = subject, EmailAddressExternal = eventReg.Attendees[0].Person.Base.EmailAddresses[0].Address, EmailAddressInternal = Settings.Default.RoughRiderEmail, NameInternal = "Texas Husky Rescue", NameExternal = string.Empty }; var emailMessageHandler = new EmailMessageHandler(); emailSendResult = emailMessageHandler.SendMessage(ref message); } catch (Exception ex) { Trace.WriteLine(ex.Message); } if (emailSendResult == ServiceResultEnum.Success) { Messages.Add("Email confirmation sent"); } return(ServiceResultEnum.Success); }
public ServiceResultEnum Create(ref Donation obj) { // Number of changes as a result of the database change NumberChanges = 0; // only perform if payment section was shown to the user if (obj.ShowPaymentSection) { // send information to payment service var paymentResult = ServiceResultEnum.Failure; var payment = obj.GetPaymentInformation(); try { var brainTreeHandler = new BrainTreeHandler(); paymentResult = brainTreeHandler.SendTransactionRequest(ref payment); if (paymentResult == ServiceResultEnum.Success) { ServiceResult = paymentResult; obj.DonationInformation.PaymentTransactionId = payment.TransactionResult.Target.Id; Messages.Add("Payment processed successfully"); } } catch (Exception ex) { Messages.Add(ex.Message); } // check if the payment was not processed if (paymentResult == ServiceResultEnum.Failure) { Messages.Add(payment.TransactionResult.Message); var errorMessage = payment.ErrorMessage(); if (errorMessage.IsNotNullOrEmpty()) { Messages.Add(errorMessage); } ServiceResult = paymentResult; return(ServiceResult); } } // payment is a success, save information to the database try { // Perform data access using the context using (var context = new HuskyRescueEntities()) { var personHandler = new PersonHandler(); var person = obj.DonationInformation.Person; if (personHandler.Create(ref person) == ServiceResultEnum.Success) { obj.DonationInformation.BaseId = person.BaseID; // convert to database object var dbObj = obj.DonationInformation.ToModel(); // add to the database and retrieve the updated object back (namely the GUID generated into the Id) dbObj = context.Entity_Donation.Add(dbObj); // commit changes to the database NumberChanges = context.SaveChanges(); // convert the database object back to a presentation object with included changes from the database (if any) obj.DonationInformation.Id = dbObj.Id; } } } catch (InvalidOperationException ex) { Trace.WriteLine(ex.Message); Messages.Add(ex.Message); } catch (DbEntityValidationException ex) { Messages.AddRange(Common.FormatEntityValidationError(ex)); } // check if database changes were a success ServiceResult = NumberChanges > 0 ? ServiceResultEnum.Success : ServiceResultEnum.Failure; if (ServiceResult == ServiceResultEnum.Success) { Messages.Add("Donation saved to database successfully"); } // if the save to database didn't work then keep going as the payment already processed. // TODO: log registration information to database for manual entry // send emails var emailSendResult = ServiceResultEnum.Failure; try { const string signature = @" Texas Husky Rescue 1-877-TX-HUSKY (894-8759) (phone/fax) PO Box 118891, Carrollton, TX 75011"; var emailBodyToDonor = new StringBuilder(); emailBodyToDonor.AppendFormat("Thank you, {0}, for your donation of {1} to Texas Husky Rescue.", obj.DonationInformation.Person.FullName, obj.DonationInformation.Amount.ToString("C")); emailBodyToDonor.AppendLine().Append(signature); var emailBodyToGroup = new StringBuilder(); emailBodyToGroup.AppendFormat("Donation received from {0} for {1}", obj.DonationInformation.Person.FullName, obj.DonationInformation.Amount.ToString("C")); if (obj.DonationInformation.DonorComments.IsNotNullOrEmpty()) { emailBodyToGroup.AppendLine().Append("Notes from donor: ").AppendLine().Append(obj.DonationInformation.DonorComments); } var message = new EmailMessage { BodyTextExternal = emailBodyToDonor.ToString(), BodyTextInternal = emailBodyToGroup.ToString(), Subject = "Texas Husky Rescue Donation", EmailAddressExternal = obj.DonationInformation.Person.Base.EmailAddresses[0].Address, EmailAddressInternal = Settings.Default.ContactEmail, NameInternal = "Texas Husky Rescue", NameExternal = string.Empty }; var emailMessageHandler = new EmailMessageHandler(); emailSendResult = emailMessageHandler.SendMessage(ref message); } catch (Exception ex) { Trace.WriteLine(ex.Message); } if (emailSendResult == ServiceResultEnum.Success) { Messages.Add("Email confirmation sent"); } return(ServiceResultEnum.Success); }
/// <summary> /// Add new EventRegistration to the database /// </summary> /// <param name="obj">EventRegistration object to be saved to the database</param> /// <returns>success or failure</returns> public ServiceResultEnum Create(ref GolfRegistration obj) { var eventReg = obj.EventRegistration; // Number of changes as a result of the database change NumberChanges = 0; // remove blank attendees eventReg.Attendees.RemoveAll(a => string.IsNullOrEmpty(a.Person.FirstName)); eventReg.Attendees.ForEach(a => a.Person.Base.EmailAddresses.RemoveAll(b => string.IsNullOrEmpty(b.Address))); eventReg.Attendees.ForEach(a => a.Person.Base.PhoneNumbers.RemoveAll(b => string.IsNullOrEmpty(b.Number))); eventReg.Event = null; // only perform if payment section was shown to the user if (obj.ShowPaymentSection) { // send information to payment service var paymentResult = ServiceResultEnum.Failure; var payment = obj.GetPaymentInformation(); try { var brainTreeHandler = new BrainTreeHandler(); paymentResult = brainTreeHandler.SendTransactionRequest(ref payment); if (paymentResult == ServiceResultEnum.Success) { ServiceResult = paymentResult; eventReg.PaymentTransactionId = payment.TransactionResult.Target.Id; eventReg.HasPaid = true; Messages.Add("Payment processed successfully"); } } catch (Exception ex) { Messages.Add(ex.Message); } // check if the payment was not processed if (paymentResult == ServiceResultEnum.Failure) { Messages.Add(payment.TransactionResult.Message); var errorMessage = payment.ErrorMessage(); if (errorMessage.IsNotNullOrEmpty()) { Messages.Add(errorMessage); } ServiceResult = paymentResult; return(ServiceResult); } } // payment is a success, save information to the database try { // Perform data access using the context using (var context = new HuskyRescueEntities()) { // convert to database object var dbObj = eventReg.ToModel(); // add to the database and retrieve the updated object back (namely the GUID generated into the Id) dbObj = context.Event_Registration.Add(dbObj); // commit changes to the database NumberChanges = context.SaveChanges(); // convert the database object back to a presentation object with included changes from the database (if any) eventReg = dbObj.ToViewModel(); } } catch (InvalidOperationException ex) { Trace.WriteLine(ex.Message); Messages.Add(ex.Message); } catch (DbEntityValidationException ex) { Messages.AddRange(Common.FormatEntityValidationError(ex)); } // check if database changes were a success ServiceResult = NumberChanges > 0 ? ServiceResultEnum.Success : ServiceResultEnum.Failure; if (ServiceResult == ServiceResultEnum.Success) { Messages.Add("Registration saved to database successfully"); } // if the save to database didn't work then keep going as the payment already processed. // TODO: log registration information to database for manual entry // send emails var emailSendResult = ServiceResultEnum.Failure; try { const string subject = "2014 TXHR Golf Tournament"; const string bodyAppHtml = @" Thank you for registering for Texas Husky Rescue's 4th Annual Golf Tournament at Coyote Ridge Golf Club! We have no doubt you will have a fabulous time all while helping to support huskies in need throughout Texas. You will be sent an email closer to the tournament with detailed information however if you have any questions prior to then, please feel free to email us at [email protected]. Thank you, Texas Husky Rescue Golf Committee 1-877-TX-HUSKY (894-8759) (phone/fax) PO Box 118891, Carrollton, TX 75011 "; var message = new EmailMessage { BodyTextExternal = bodyAppHtml, BodyTextInternal = eventReg.RegistrationDescription, Subject = subject, EmailAddressExternal = eventReg.Attendees[0].Person.Base.EmailAddresses[0].Address, EmailAddressInternal = Settings.Default.ContactEmail, NameInternal = "Texas Husky Rescue", NameExternal = string.Empty }; var emailMessageHandler = new EmailMessageHandler(); emailSendResult = emailMessageHandler.SendMessage(ref message); } catch (Exception ex) { Trace.WriteLine(ex.Message); } if (emailSendResult == ServiceResultEnum.Success) { Messages.Add("Email confirmation sent"); } return(ServiceResultEnum.Success); }