public async Task <IHttpActionResult> Reminders() { try { EmailService emailService = new EmailService(); SmsService smsService = new SmsService(); foreach (SimpleBooking simpleBooking in GetBookings()) { string message = $"Dear, {simpleBooking.Name}, you have an appointment with {simpleBooking.With}, for a {simpleBooking.For} at {simpleBooking.DateTime}"; if (!string.IsNullOrWhiteSpace(simpleBooking.EmailAddress)) { try { await emailService.SendAsync(new IdentityMessage() { Body = message, Destination = simpleBooking.EmailAddress, Subject = "Booking Reminder" }); } catch (Exception exception) { } } if (!string.IsNullOrWhiteSpace(simpleBooking.PhoneNumber)) { try { var client = new MScience.Sms.SmsClient { // AccountId = ConfigurationManager.AppSettings["DragonFlyAccountId"], Password = ConfigurationManager.AppSettings["DragonFlyPassword"] }; var sendResult = client.Send(simpleBooking.PhoneNumber, "", message, 0, true); } catch (Exception exception) { return(Content(HttpStatusCode.BadGateway, exception.Message)); } } } return(Ok(GetBookings())); } catch (Exception exception) { return(Ok(exception.Message)); } }
public async Task <IHttpActionResult> Sms(string phoneNumber, string text) { var client = new MScience.Sms.SmsClient { // AccountId = ConfigurationManager.AppSettings["DragonFlyAccountId"], Password = ConfigurationManager.AppSettings["DragonFlyPassword"] }; var sendResult = client.Send(phoneNumber, "", text, 0, true); if (sendResult.HasError) { BadRequest(); } var deliveryReceipts = client.GetDeliveryReceipts(); return(Ok(deliveryReceipts)); }