# Workflow Automation with C# and ASP.NET MVC

One of the more abstract concepts you'll handle when building your business is what the *workflow* will look like.

At its core, setting up a standardized workflow is about enabling your service providers (agents, hosts, customer service reps, administrators, and the rest of the gang) to better serve your customers.

To illustrate a very real-world example, today we'll build a C# and ASP.NET MVC webapp for finding and booking vacation properties — tentatively called ***Airtng***.

Here's how it'll work:

1. A *host* creates a vacation property listing
2. A *guest* requests a reservation for a property
3. The *host* receives an SMS notifying them of the reservation request. The host can either **Accept** or **Reject** the reservation
4. The *guest* is notified whether a request was rejected or accepted

*[Learn how Airbnb used Twilio SMS to streamline the rental experience for 60M+ travelers around the world.](https://customers.twilio.com/214/airbnb/)*

## Workflow Building Blocks

We'll be using the Twilio REST API to send our users messages at important junctures. Here's a bit more on our API:

* Sending Messages with Twilio API

```cs title="Notify the host" description="AirTNG.Web/Domain/Reservations/Notifier.cs"
// !mark(32:39)
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirTNG.Web.Domain.Twilio;
using AirTNG.Web.Models;
using AirTNG.Web.Models.Repository;

namespace AirTNG.Web.Domain.Reservations
{
    public interface INotifier
    {
        Task SendNotificationAsync(Reservation reservation);
    }

    public class Notifier : INotifier
    {
        private readonly ITwilioMessageSender _client;
        private readonly IReservationsRepository _repository;

        public Notifier() : this(
            new TwilioMessageSender(),
            new ReservationsRepository()) { }

        public Notifier(ITwilioMessageSender client, IReservationsRepository repository)
        {
            _client = client;
            _repository = repository;
        }

        public async Task SendNotificationAsync(Reservation reservation)
        {
            var pendingReservations = await _repository.FindPendingReservationsAsync();
            if (pendingReservations.Count() < 2)
            {
                var notification = BuildNotification(reservation);
                await _client.SendMessageAsync(notification.To, notification.From, notification.Messsage);
            }
        }

        private static Notification BuildNotification(Reservation reservation)
        {
            var message = new StringBuilder();
            message.AppendFormat("You have a new reservation request from {0} for {1}:{2}",
                reservation.Name,
                reservation.VacationProperty.Description,
                Environment.NewLine);
            message.AppendFormat("{0}{1}",
                reservation.Message,
                Environment.NewLine);
            message.Append("Reply [accept] or [reject]");

            return new Notification
            {
                From = PhoneNumbers.Twilio,
                To = reservation.PhoneNumber,
                Messsage = message.ToString()
            };
        }
    }
}
```

Ready to go? Boldly click the button right after this sentence.

## Authenticate Users

For this use case to work we have to handle authentication. We will rely on [*ASP.NET Identity*](https://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity) for this purpose.

Each `User` will need to have a `phone_number` that we will use later to send SMS notifications.

```cs title="The User model" description="AirTNG.Web/Models/IdentityModels.cs"
// !mark(10:24)
using System.Collections.Generic;
using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;

namespace AirTNG.Web.Models
{
    // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
    public class ApplicationUser : IdentityUser
    {
        public string Name { get; set; }

        public virtual IList<VacationProperty> VacationProperties { get; set; }

        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            return userIdentity;
        }
    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("AirTNGConnection", false)
        {
        }

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }

        public DbSet<VacationProperty> VacationProperties { get; set; }
        public DbSet<Reservation> Reservations { get; set; }
    }
}
```

Next let's take a look at the Vacation Property model.

## The Vacation Property Model

Our rental application will require listing properties.

The `VacationProperty` belongs to the `User` who created it (we'll call this user the *host* from this point on) and contains only two properties: a `Description` and an `ImageUrl`.

A `VacationProperty` can have many `Reservations.`

```cs title="Vacation Property Model" description="AirTNG.Web/Models/VacationProperty.cs"
// !mark(6:15)
using System;
using System.Collections.Generic;

namespace AirTNG.Web.Models
{
    public class VacationProperty
    {
        public int Id { get; set; }
        public string UserId { get; set; }
        public virtual ApplicationUser User { get; set; }
        public string Description { get; set; }
        public string ImageUrl { get; set; }
        public DateTime CreatedAt { get; set; }
        public virtual IList<Reservation> Reservations { get; set; }
    }
}
```

Next, let's see what our Reservation model looks like.

## Reservation Model

The `Reservation` model is at the center of the workflow for this application.

It is responsible for keeping track of:

* The `VacationProperty` it is associated with.
* The `User` who owns that vacation property (the host). Through this property the user will have access to the *host* phone number indirectly.
* The `Status` of the reservation

```cs title="The Reservation Model" description="AirTNG.Web/Models/Reservation.cs"
// !mark(6:17)
using System;
using System.ComponentModel.DataAnnotations.Schema;

namespace AirTNG.Web.Models
{
    public class Reservation
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string PhoneNumber { get; set; }
        public ReservationStatus Status { get; set; }
        public string Message { get; set; }
        public DateTime CreatedAt { get; set; }
        public int VactionPropertyId { get; set; }
        [ForeignKey("VactionPropertyId")]
        public virtual VacationProperty VacationProperty { get; set; }
    }
}
```

Now that our models are ready, let's have a look at the controller that will create reservations.

## Create a Reservation

The reservation creation form holds only a single field: the message that will be sent to the *host* when one of her properties is reserved. The rest of the information needed to create a reservation is taken from the VacationProperty itself.

A reservation is created with a default status `ReservationStatus.Pending`. That way when the *host* replies with an `accept` or `reject` response the application knows which reservation to update.

```cs title="The Reservations Controller" description="AirTNG.Web/Controllers/ReservationsController.cs"
// !mark(56:80)
using System;
using System.Threading.Tasks;
using System.Web.Mvc;
using AirTNG.Web.Domain.Reservations;
using AirTNG.Web.Models;
using AirTNG.Web.Models.Repository;
using AirTNG.Web.ViewModels;
using Twilio.AspNet.Mvc;
using Twilio.TwiML;

namespace AirTNG.Web.Controllers
{
    [Authorize]
    public class ReservationsController : TwilioController
    {
        private readonly IVacationPropertiesRepository _vacationPropertiesRepository;
        private readonly IReservationsRepository _reservationsRepository;
        private readonly IUsersRepository _usersRepository;
        private readonly INotifier _notifier;

        public ReservationsController() : this(
            new VacationPropertiesRepository(),
            new ReservationsRepository(),
            new UsersRepository(),
            new Notifier()) { }

        public ReservationsController(
            IVacationPropertiesRepository vacationPropertiesRepository,
            IReservationsRepository reservationsRepository,
            IUsersRepository usersRepository,
            INotifier notifier)
        {
            _vacationPropertiesRepository = vacationPropertiesRepository;
            _reservationsRepository = reservationsRepository;
            _usersRepository = usersRepository;
            _notifier = notifier;
        }

        // GET: Reservations/Create
        public async Task<ActionResult> Create(int id)
        {
            var vacationProperty = await _vacationPropertiesRepository.FindAsync(id);
            var reservation = new ReservationViewModel
            {
                ImageUrl = vacationProperty.ImageUrl,
                Description = vacationProperty.Description,
                VacationPropertyId = vacationProperty.Id,
                VacationPropertyDescription = vacationProperty.Description,
                UserName = vacationProperty.User.Name,
                UserPhoneNumber = vacationProperty.User.PhoneNumber,
            };

            return View(reservation);
        }

        // POST: Reservations/Create
        [HttpPost]
        public async Task<ActionResult> Create(ReservationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var reservation = new Reservation
                {
                    Message = model.Message,
                    PhoneNumber = model.UserPhoneNumber,
                    Name = model.UserName,
                    VactionPropertyId = model.VacationPropertyId,
                    Status = ReservationStatus.Pending,
                    CreatedAt = DateTime.Now
                };

                await _reservationsRepository.CreateAsync(reservation);
                reservation.VacationProperty = new VacationProperty {Description = model.VacationPropertyDescription};
                await _notifier.SendNotificationAsync(reservation);

                return RedirectToAction("Index", "VacationProperties");
            }

            return View(model);
        }

        // POST Reservations/Handle
        [HttpPost]
        [AllowAnonymous]
        public async Task<TwiMLResult> Handle(string from, string body)
        {
            string smsResponse;

            try
            {
                var host = await _usersRepository.FindByPhoneNumberAsync(from);
                var reservation = await _reservationsRepository.FindFirstPendingReservationByHostAsync(host.Id);

                var smsRequest = body;
                reservation.Status =
                    smsRequest.Equals("accept", StringComparison.InvariantCultureIgnoreCase) ||
                    smsRequest.Equals("yes", StringComparison.InvariantCultureIgnoreCase)
                    ? ReservationStatus.Confirmed
                    : ReservationStatus.Rejected;

                await _reservationsRepository.UpdateAsync(reservation);
                smsResponse =
                    string.Format("You have successfully {0} the reservation", reservation.Status);
            }
            catch (Exception)
            {
                smsResponse = "Sorry, it looks like you don't have any reservations to respond to.";
            }

            return TwiML(Respond(smsResponse));
        }

        private static MessagingResponse Respond(string message)
        {
            var response = new MessagingResponse();
            response.Message(message);

            return response;
        }
    }
}
```

Next, let's see how we will send SMS notifications to the vacation rental host.

## Notify The Host

When a reservation is created we want to notify the owner of the property that someone is interested.

This is where we use [Twilio C# SDK](https://github.com/twilio/twilio-csharp) to send a SMS message to the *host*, using our [Twilio phone number](https://twilio.com/console). As you can see, sending SMS messages using Twilio takes just a few lines of code.

Next we just have to wait for the host to send an SMS response accepting or rejecting the reservation. Then we can notify the guest and host that the reservation information has been updated.

```cs title="Notify the host" description="AirTNG.Web/Domain/Reservations/Notifier.cs"
// !mark(32:39)
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirTNG.Web.Domain.Twilio;
using AirTNG.Web.Models;
using AirTNG.Web.Models.Repository;

namespace AirTNG.Web.Domain.Reservations
{
    public interface INotifier
    {
        Task SendNotificationAsync(Reservation reservation);
    }

    public class Notifier : INotifier
    {
        private readonly ITwilioMessageSender _client;
        private readonly IReservationsRepository _repository;

        public Notifier() : this(
            new TwilioMessageSender(),
            new ReservationsRepository()) { }

        public Notifier(ITwilioMessageSender client, IReservationsRepository repository)
        {
            _client = client;
            _repository = repository;
        }

        public async Task SendNotificationAsync(Reservation reservation)
        {
            var pendingReservations = await _repository.FindPendingReservationsAsync();
            if (pendingReservations.Count() < 2)
            {
                var notification = BuildNotification(reservation);
                await _client.SendMessageAsync(notification.To, notification.From, notification.Messsage);
            }
        }

        private static Notification BuildNotification(Reservation reservation)
        {
            var message = new StringBuilder();
            message.AppendFormat("You have a new reservation request from {0} for {1}:{2}",
                reservation.Name,
                reservation.VacationProperty.Description,
                Environment.NewLine);
            message.AppendFormat("{0}{1}",
                reservation.Message,
                Environment.NewLine);
            message.Append("Reply [accept] or [reject]");

            return new Notification
            {
                From = PhoneNumbers.Twilio,
                To = reservation.PhoneNumber,
                Messsage = message.ToString()
            };
        }
    }
}
```

Now's let's peek at how we're handling the host's responses.

## Handle Incoming Messages

The `Reservations/Handle` controller handles our incoming Twilio request and does four things:

1. Check for the guest's pending reservation
2. Update the status of the reservation
3. Respond to the host
4. Send notification to the guest

```cs title="Handle a host response" description="AirTNG.Web/Controllers/ReservationsController.cs"
// !mark(82:111)
using System;
using System.Threading.Tasks;
using System.Web.Mvc;
using AirTNG.Web.Domain.Reservations;
using AirTNG.Web.Models;
using AirTNG.Web.Models.Repository;
using AirTNG.Web.ViewModels;
using Twilio.AspNet.Mvc;
using Twilio.TwiML;

namespace AirTNG.Web.Controllers
{
    [Authorize]
    public class ReservationsController : TwilioController
    {
        private readonly IVacationPropertiesRepository _vacationPropertiesRepository;
        private readonly IReservationsRepository _reservationsRepository;
        private readonly IUsersRepository _usersRepository;
        private readonly INotifier _notifier;

        public ReservationsController() : this(
            new VacationPropertiesRepository(),
            new ReservationsRepository(),
            new UsersRepository(),
            new Notifier()) { }

        public ReservationsController(
            IVacationPropertiesRepository vacationPropertiesRepository,
            IReservationsRepository reservationsRepository,
            IUsersRepository usersRepository,
            INotifier notifier)
        {
            _vacationPropertiesRepository = vacationPropertiesRepository;
            _reservationsRepository = reservationsRepository;
            _usersRepository = usersRepository;
            _notifier = notifier;
        }

        // GET: Reservations/Create
        public async Task<ActionResult> Create(int id)
        {
            var vacationProperty = await _vacationPropertiesRepository.FindAsync(id);
            var reservation = new ReservationViewModel
            {
                ImageUrl = vacationProperty.ImageUrl,
                Description = vacationProperty.Description,
                VacationPropertyId = vacationProperty.Id,
                VacationPropertyDescription = vacationProperty.Description,
                UserName = vacationProperty.User.Name,
                UserPhoneNumber = vacationProperty.User.PhoneNumber,
            };

            return View(reservation);
        }

        // POST: Reservations/Create
        [HttpPost]
        public async Task<ActionResult> Create(ReservationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var reservation = new Reservation
                {
                    Message = model.Message,
                    PhoneNumber = model.UserPhoneNumber,
                    Name = model.UserName,
                    VactionPropertyId = model.VacationPropertyId,
                    Status = ReservationStatus.Pending,
                    CreatedAt = DateTime.Now
                };

                await _reservationsRepository.CreateAsync(reservation);
                reservation.VacationProperty = new VacationProperty {Description = model.VacationPropertyDescription};
                await _notifier.SendNotificationAsync(reservation);

                return RedirectToAction("Index", "VacationProperties");
            }

            return View(model);
        }

        // POST Reservations/Handle
        [HttpPost]
        [AllowAnonymous]
        public async Task<TwiMLResult> Handle(string from, string body)
        {
            string smsResponse;

            try
            {
                var host = await _usersRepository.FindByPhoneNumberAsync(from);
                var reservation = await _reservationsRepository.FindFirstPendingReservationByHostAsync(host.Id);

                var smsRequest = body;
                reservation.Status =
                    smsRequest.Equals("accept", StringComparison.InvariantCultureIgnoreCase) ||
                    smsRequest.Equals("yes", StringComparison.InvariantCultureIgnoreCase)
                    ? ReservationStatus.Confirmed
                    : ReservationStatus.Rejected;

                await _reservationsRepository.UpdateAsync(reservation);
                smsResponse =
                    string.Format("You have successfully {0} the reservation", reservation.Status);
            }
            catch (Exception)
            {
                smsResponse = "Sorry, it looks like you don't have any reservations to respond to.";
            }

            return TwiML(Respond(smsResponse));
        }

        private static MessagingResponse Respond(string message)
        {
            var response = new MessagingResponse();
            response.Message(message);

            return response;
        }
    }
}
```

Let's have closer look at how Twilio webhooks are configured to enable incoming requests to our application.

## Incoming Twilio Requests

In the [Twilio console](https://twilio.com/console), you must setup the SMS webhook to call your application's end point in the route `Reservations/Handle`.

![Messaging configuration with webhook URL set to https://yourserver.com/sms.](https://docs-resources.prod.twilio.com/f25966b33e960a4214a186c1dbdd0d35aff94f3b3c704f7db85ba8a082ec20d2.png)

One way to expose your development machine to the outside world is using [ngrok](https://ngrok.com/). The URL for the SMS webhook on your number would look like this:

```bash
http://<subdomain>.ngrok.io/Reservations/Handle

```

An incoming request from Twilio comes with some helpful parameters, such as a `from` phone number and the message `body`.

We'll use the `from` parameter to look for the *host* and check if they have any pending reservations. If they do, we'll use the message body to check for 'accept' and 'reject'.

In the last step, we'll use [Twilio's TwiML](/docs/glossary/what-is-twilio-markup-language-twiml) as a response to Twilio to send an SMS message to the *guest*.

```cs title="Accept or reject a reservation" description="AirTNG.Web/Controllers/ReservationsController.cs"
// !mark(82:111)
using System;
using System.Threading.Tasks;
using System.Web.Mvc;
using AirTNG.Web.Domain.Reservations;
using AirTNG.Web.Models;
using AirTNG.Web.Models.Repository;
using AirTNG.Web.ViewModels;
using Twilio.AspNet.Mvc;
using Twilio.TwiML;

namespace AirTNG.Web.Controllers
{
    [Authorize]
    public class ReservationsController : TwilioController
    {
        private readonly IVacationPropertiesRepository _vacationPropertiesRepository;
        private readonly IReservationsRepository _reservationsRepository;
        private readonly IUsersRepository _usersRepository;
        private readonly INotifier _notifier;

        public ReservationsController() : this(
            new VacationPropertiesRepository(),
            new ReservationsRepository(),
            new UsersRepository(),
            new Notifier()) { }

        public ReservationsController(
            IVacationPropertiesRepository vacationPropertiesRepository,
            IReservationsRepository reservationsRepository,
            IUsersRepository usersRepository,
            INotifier notifier)
        {
            _vacationPropertiesRepository = vacationPropertiesRepository;
            _reservationsRepository = reservationsRepository;
            _usersRepository = usersRepository;
            _notifier = notifier;
        }

        // GET: Reservations/Create
        public async Task<ActionResult> Create(int id)
        {
            var vacationProperty = await _vacationPropertiesRepository.FindAsync(id);
            var reservation = new ReservationViewModel
            {
                ImageUrl = vacationProperty.ImageUrl,
                Description = vacationProperty.Description,
                VacationPropertyId = vacationProperty.Id,
                VacationPropertyDescription = vacationProperty.Description,
                UserName = vacationProperty.User.Name,
                UserPhoneNumber = vacationProperty.User.PhoneNumber,
            };

            return View(reservation);
        }

        // POST: Reservations/Create
        [HttpPost]
        public async Task<ActionResult> Create(ReservationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var reservation = new Reservation
                {
                    Message = model.Message,
                    PhoneNumber = model.UserPhoneNumber,
                    Name = model.UserName,
                    VactionPropertyId = model.VacationPropertyId,
                    Status = ReservationStatus.Pending,
                    CreatedAt = DateTime.Now
                };

                await _reservationsRepository.CreateAsync(reservation);
                reservation.VacationProperty = new VacationProperty {Description = model.VacationPropertyDescription};
                await _notifier.SendNotificationAsync(reservation);

                return RedirectToAction("Index", "VacationProperties");
            }

            return View(model);
        }

        // POST Reservations/Handle
        [HttpPost]
        [AllowAnonymous]
        public async Task<TwiMLResult> Handle(string from, string body)
        {
            string smsResponse;

            try
            {
                var host = await _usersRepository.FindByPhoneNumberAsync(from);
                var reservation = await _reservationsRepository.FindFirstPendingReservationByHostAsync(host.Id);

                var smsRequest = body;
                reservation.Status =
                    smsRequest.Equals("accept", StringComparison.InvariantCultureIgnoreCase) ||
                    smsRequest.Equals("yes", StringComparison.InvariantCultureIgnoreCase)
                    ? ReservationStatus.Confirmed
                    : ReservationStatus.Rejected;

                await _reservationsRepository.UpdateAsync(reservation);
                smsResponse =
                    string.Format("You have successfully {0} the reservation", reservation.Status);
            }
            catch (Exception)
            {
                smsResponse = "Sorry, it looks like you don't have any reservations to respond to.";
            }

            return TwiML(Respond(smsResponse));
        }

        private static MessagingResponse Respond(string message)
        {
            var response = new MessagingResponse();
            response.Message(message);

            return response;
        }
    }
}
```

Now that we know how to expose a webhook to handle Twilio requests, let's see how we generate the TwiML needed.

## TwiML Response

After updating the reservation status, we must notify the *host* that they have successfully confirmed or rejected the reservation. We also have to return a friendly error message if there are no pending reservations.

If the reservation is *confirmed* or *rejected* we send an additional SMS to the *guest* to deliver the news.

We use the verb [Message](/docs/messaging/twiml/message) from TwiML to instruct Twilio's server that it should send the SMS messages.

```cs title="Respond to a message" description="AirTNG.Web/Controllers/ReservationsController.cs"
// !mark(113:119)
using System;
using System.Threading.Tasks;
using System.Web.Mvc;
using AirTNG.Web.Domain.Reservations;
using AirTNG.Web.Models;
using AirTNG.Web.Models.Repository;
using AirTNG.Web.ViewModels;
using Twilio.AspNet.Mvc;
using Twilio.TwiML;

namespace AirTNG.Web.Controllers
{
    [Authorize]
    public class ReservationsController : TwilioController
    {
        private readonly IVacationPropertiesRepository _vacationPropertiesRepository;
        private readonly IReservationsRepository _reservationsRepository;
        private readonly IUsersRepository _usersRepository;
        private readonly INotifier _notifier;

        public ReservationsController() : this(
            new VacationPropertiesRepository(),
            new ReservationsRepository(),
            new UsersRepository(),
            new Notifier()) { }

        public ReservationsController(
            IVacationPropertiesRepository vacationPropertiesRepository,
            IReservationsRepository reservationsRepository,
            IUsersRepository usersRepository,
            INotifier notifier)
        {
            _vacationPropertiesRepository = vacationPropertiesRepository;
            _reservationsRepository = reservationsRepository;
            _usersRepository = usersRepository;
            _notifier = notifier;
        }

        // GET: Reservations/Create
        public async Task<ActionResult> Create(int id)
        {
            var vacationProperty = await _vacationPropertiesRepository.FindAsync(id);
            var reservation = new ReservationViewModel
            {
                ImageUrl = vacationProperty.ImageUrl,
                Description = vacationProperty.Description,
                VacationPropertyId = vacationProperty.Id,
                VacationPropertyDescription = vacationProperty.Description,
                UserName = vacationProperty.User.Name,
                UserPhoneNumber = vacationProperty.User.PhoneNumber,
            };

            return View(reservation);
        }

        // POST: Reservations/Create
        [HttpPost]
        public async Task<ActionResult> Create(ReservationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var reservation = new Reservation
                {
                    Message = model.Message,
                    PhoneNumber = model.UserPhoneNumber,
                    Name = model.UserName,
                    VactionPropertyId = model.VacationPropertyId,
                    Status = ReservationStatus.Pending,
                    CreatedAt = DateTime.Now
                };

                await _reservationsRepository.CreateAsync(reservation);
                reservation.VacationProperty = new VacationProperty {Description = model.VacationPropertyDescription};
                await _notifier.SendNotificationAsync(reservation);

                return RedirectToAction("Index", "VacationProperties");
            }

            return View(model);
        }

        // POST Reservations/Handle
        [HttpPost]
        [AllowAnonymous]
        public async Task<TwiMLResult> Handle(string from, string body)
        {
            string smsResponse;

            try
            {
                var host = await _usersRepository.FindByPhoneNumberAsync(from);
                var reservation = await _reservationsRepository.FindFirstPendingReservationByHostAsync(host.Id);

                var smsRequest = body;
                reservation.Status =
                    smsRequest.Equals("accept", StringComparison.InvariantCultureIgnoreCase) ||
                    smsRequest.Equals("yes", StringComparison.InvariantCultureIgnoreCase)
                    ? ReservationStatus.Confirmed
                    : ReservationStatus.Rejected;

                await _reservationsRepository.UpdateAsync(reservation);
                smsResponse =
                    string.Format("You have successfully {0} the reservation", reservation.Status);
            }
            catch (Exception)
            {
                smsResponse = "Sorry, it looks like you don't have any reservations to respond to.";
            }

            return TwiML(Respond(smsResponse));
        }

        private static MessagingResponse Respond(string message)
        {
            var response = new MessagingResponse();
            response.Message(message);

            return response;
        }
    }
}
```

Congratulations! You've just learned how to automate your workflow with Twilio SMS.

Next, lets see what else we can do with the Twilio C# SDK.

## Where to Next?

If you're a .NET developer working with Twilio you know we've got a lot of great content here on the Docs site. Here are just a couple ideas for your next tutorial:

**[IVR: Phone Tree](/docs/voice/tutorials/build-interactive-voice-response-ivr-phone-tree/csharp)**

You can route callers to the right people and information with an IVR (interactive voice response) system.

**[Automated Survey](/blog/automated-survey-csharp-aspnet-mvc)**

Instantly collect structured data from your users with a survey conducted over a voice call or SMS text messages.
