public async Task <ActionResult> Create([Bind("Id,AppointmentName,AppointmentDate,AppointmentDetails")] Appointment appointment)
        {
            var userId   = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var customer = _repo.Customer.GetCustomer(userId);

            appointment.CustomerId = customer.Id;
            TwilioService.SendTextMessage(customer, appointment);
            _context.Add(appointment);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Appointments"));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,AppointmentName,AppointmentDate,AppointmentDetails")] Appointment appointment)
        {
            if (id != appointment.Id)
            {
                return(NotFound());
            }
            var userId              = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var customer            = _context.Customers.Where(c => c.IdentityUserId == userId).SingleOrDefault();
            var appointmentToUpdate = _context.Appointments.Where(a => a.Id == id).SingleOrDefault();

            appointmentToUpdate.Id         = id;
            appointmentToUpdate.CustomerId = customer.Id;
            appointmentToUpdate            = UpdateAppointment(appointment, appointmentToUpdate);
            if (ModelState.IsValid)
            {
                try
                {
                    TwilioService.SendTextMessage(customer, appointment);
                    _context.Appointments.Update(appointmentToUpdate);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AppointmentExists(appointment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index", "Appointments"));
            }
            return(RedirectToAction("Index", "Appointments"));
        }
Exemple #3
0
 public void TestTextSucceeds()
 {
     _mockLogger.Setup(mock => mock.Error(It.IsAny <string>())).Verifiable();
     _fixture.SendTextMessage("+15005550006", "Hi");
     _mockLogger.Verify(mock => mock.Error(It.IsAny <string>()), Times.Never);
 }