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; } }
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(); }
private AppointmentModel GenerateApptModel(Appointment appointment) { var servicesSb = new StringBuilder(); for (var i = 0; i < appointment.Services.Count; i++) { var svc = appointment.Services[i]; servicesSb.Append(svc.Name); if (i < appointment.Services.Count - 1) servicesSb.Append(", "); } return new AppointmentModel { Id = appointment.Id, Title = string.Format("{0} - {1}", appointment.FirstName, servicesSb.ToString()), FirstName = appointment.FirstName, Description = appointment.PhoneNumber, EstheticianId = appointment.EstheticianId, Services = new List<SpaServiceViewModel>(appointment.Services.Select(x => new SpaServiceViewModel { Name = x.Name, Id = x.Id })), LocationId = appointment.LocationId, Start = appointment.StartTime.ToLocalTime(), End = appointment.EndTime.ToLocalTime(), IsNoShow = appointment.IsNoShow, Gender = appointment.Gender }; }