private void ConfirmationEmail(Data.Models.Payment.Order order, SystemModel settings, string name, bool isCustomer = true) { try { var subject = $"{settings.Get(SettingName.Title)} - Order Confirmation {order.Id}"; if (isCustomer) { EmailSender.Send(_azureSettings.SendgridApiKey, subject, GetBody(order, name, settings, true), order.Email, settings.Get(SettingName.ContactEmail)); } else { var emailsString = settings.Get(SettingName.OrderNotificationEmails); if (!string.IsNullOrWhiteSpace(emailsString)) { var emails = emailsString.Split(new[] { ',', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries).Where(x => x.Length > 5 && x.Contains("@")); foreach (var email in emails) { try { EmailSender.Send(_azureSettings.SendgridApiKey, subject, GetBody(order, name, settings, false), email, settings.Get(SettingName.ContactEmail)); } catch (Exception ex) { Log(ex); } } } } } catch (Exception ex) { Log(ex); if (isCustomer) { throw new Exception("Order placed successfully but there was an error sending confirmation email - don't worry, your food will be ready!"); } } }
public LocationModel Location() { var locationIdString = _settings.Get(SettingName.Location); int locationId; return(int.TryParse(locationIdString, out locationId) ? new LocationHandler(_context, "system").Get(locationId) : new LocationModel()); }
private string GetBody(Data.Models.Payment.Order order, string name, SystemModel settings, bool isCustomer) { var n = Environment.NewLine; var title = settings.Get(SettingName.Title); var customerInfo = string.Join(", ", new[] { name, order.Email, order.Phone }.Where(x => !string.IsNullOrWhiteSpace(x))); return(isCustomer ? $"{title} Order Confirmation:{n}{n}{order.FullText}{n}{n}Thank you!{n}-{title}" : $"Order for {customerInfo}{n}{n}{order.FullText}"); }
private void ConfirmationText(Data.Models.Payment.Order order, SystemModel settings, string name, bool isCustomer = true) { try { var twilio = new TwilioHelper(settings.Get(SettingName.TwilioAuthToken), settings.Get(SettingName.TwilioSid), settings.Get(SettingName.TwilioPhoneNumber)); if (twilio.IsValid) { ISmsSender smsSender = new TwilioSmsSender(twilio.Sid, twilio.AuthToken); if (isCustomer && !string.IsNullOrWhiteSpace(order.Phone)) { smsSender.Send(twilio.Phone, order.Phone, GetBody(order, name, settings, true)); } if (!isCustomer) { var phoneNumbersString = settings.Get(SettingName.OrderNotificationPhoneNumbers); if (!string.IsNullOrWhiteSpace(phoneNumbersString)) { var phoneNumbers = phoneNumbersString.Split(new[] { ',', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries).Where(x => x.Length == 10 && x.All(c => char.IsDigit(c))); foreach (var phoneNumber in phoneNumbers) { try { smsSender.Send(twilio.Phone, $"+1{phoneNumber}", GetBody(order, name, settings, false)); } catch (Exception ex) { Log(ex); } } } } } } catch (Exception ex) { Log(ex); if (isCustomer) { throw new Exception("Order placed successfully but there was an error sending confirmation text - don't worry, your food will be ready!"); } } }