public void AddAppointmentMethod_ThrowsNoException()
        {
            // ARRANGE
            var newAppt = new AppointmentModel
            {
                Id = 1,
                AppointmentTime = new DateTime(2018, 12, 1, 11, 00, 00),
                ProviderId      = 2
            };
            var    testRepo = new Repository(CreateSpaAppContext(), CreateTestReadOnlyContext());
            string message  = null;

            //ACT
            try
            {
                testRepo.AddAppointment(newAppt);
            }
            //ASSERT
            catch (Exception e)
            {
                message = e.ToString();
            }

            Assert.Null(message);
        }
        public void AddAppointmentMethod_ThrowsExceptionWhenProviderIsNotAvailable()
        {
            // ARRANGE
            var newAppt = new AppointmentModel
            {
                Id = 2,
                AppointmentTime = new DateTime(2018, 12, 1, 11, 00, 00),
                ProviderId      = 1
            };
            var testRepo = new Repository(CreateSpaAppContext(), CreateTestReadOnlyContext());

            //ACT & ASSERT
            Assert.Throws <System.Exception>(() => testRepo.AddAppointment(newAppt));
        }
        public IActionResult AppointmentCreate(Appointment appointment)
        {
            bool custExists            = false;
            bool serviceProviderExists = false;
            bool doubleBooked          = false;

            foreach (var c in Repository.Customers)
            {
                if (appointment.Customer == c.Name)
                {
                    custExists = true;
                }
            }
            foreach (var s in Repository.ServiceProviders)
            {
                if (appointment.ServiceProvider == s.Name)
                {
                    serviceProviderExists = true;
                }
            }
            foreach (var a in Repository.Appointments)
            {
                if (appointment.Date == a.Date && appointment.Time == a.Time && (appointment.Customer == a.Customer || appointment.ServiceProvider == a.ServiceProvider))
                {
                    doubleBooked = true;
                }
            }
            if (custExists && serviceProviderExists && !doubleBooked)
            {
                Repository.AddAppointment(appointment);
            }
            else
            {
                ViewBag.error = "Invalid Appointment";
            }
            return(View("AppointmentIndex", Repository.Appointments.OrderBy(a => a.Date).ThenBy(a => a.Time)));
        }