private static void AddAppointments(SMDbContext context, UserManager<ApplicationUser> userManager)
        {
            var esth = context.Estheticians.Single(x => x.Id == 1);
            var services = context.SpaServices.Take(3).ToList();
            var clientUser = new ApplicationUser
            {
                UserName = "******",
                Email = "*****@*****.**",
                FirstName = "Claire",
                LastName = "Smith",
                PhoneNumber = "5625551212"
            };

            Task.FromResult(userManager.CreateAsync(clientUser, "client11").Result);

            var client = new Client
            {
                ApplicationUserId = userManager.FindByEmailAsync("*****@*****.**").Result.Id,
                AppointmentRemindersViaText = true,
                Appointments = new List<Appointment>()
            };
            context.Clients.Add(client);
            context.SaveChanges();

            var appt = new Appointment
            {
                ClientId = client.Id,
                FirstName = clientUser.FirstName,
                LastName = clientUser.LastName,
                Email = clientUser.Email,
                PhoneNumber = clientUser.PhoneNumber,
                Services = services,
                Esthetician = esth,
                StartTime = DateTime.Parse("10/21/2016 17:15"),
                LocationId = 1,
                EndTime = DateTime.Parse("10/21/2016 18:30"),
                RemindViaEmail = client.AppointmentRemindersViaEmail,
                RemindViaText = client.AppointmentRemindersViaText,
                Gender = Gender.Male
            };

            context.Appointments.Add(appt);
            context.SaveChanges();
        }
        public async Task<Appointment> BookAppointmentAsync(AppointmentBookingModel model)
        {
            var esth = _estheticians.GetByIdAsync(model.SelectedEsthetician.Id, x => x.User);
            var services = await _spaServices.FindAsync(x => model.SelectedServices.Select(o => o.Id).Contains(x.Id));
            Client client = null;

            //Create the user if they added a password
            if (model.Password != null)
            {
                var clientUser = new ApplicationUser
                {
                    UserName = model.Email,
                    Email = model.Email,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    PhoneNumber = model.PhoneNumber
                };
                await Task.FromResult(_users.CreateAsync(clientUser, model.Password).Result);

                client = new Client
                {
                    ApplicationUserId = _users.FindByEmailAsync(model.Email).Result.Id,
                    AppointmentRemindersViaText = model.ReminderViaText,
                    AppointmentRemindersViaEmail = model.ReminderViaEmail,
                    Appointments = new List<Appointment>()
                };

            }

            var appt = new Appointment
            {
                Services = services.ToList(),
                Esthetician = await esth,
                StartTime = model.StartTime.ToUniversalTime(),
                EndTime = model.EndTime.ToUniversalTime(),
                RemindViaEmail = model.ReminderViaEmail,
                RemindViaText = model.ReminderViaText,
                FirstName = model.FirstName,
                LastName = model.LastName,
                Email = model.Email,
                PhoneNumber = model.PhoneNumber,
                LocationId = model.SelectedLocationId,
                Gender = model.Gender
            };

            //appt.Cost = appt.Services.Sum(x => x.Cost);

            //link the created user, if any
            if (client != null)
            {
                appt.Client = client;
            }
            try
            {
                return await _appointments.AddAsync(appt);

            }
            catch (Exception ex)
            {
                
                throw ex;
            }
        }