Beispiel #1
0
        public ActionResult DeleteClinicDay(int id)
        {
            // get clinic day
            var clinicDay = _clinicRepository.GetClinicDay(id);

            if (clinicDay != null)
            {
                // convert day to enum day
                var day     = Convert.ToString(clinicDay.Day);
                var enumDay = ((DayOfWeek)Enum.Parse(typeof(DayOfWeek), day));

                // check if there are future appointments booked on this day
                var appExists = _appointmentRepository.Appointments
                                .Where(s => s.Date >= DateTime.Today)
                                .Any(s => s.Date.DayOfWeek == enumDay);

                if (appExists)
                {
                    // return to index with error
                    ViewBag.Error = $"Failed to delete {day}. There are future appointments booked on this day";

                    return(View("Index"));
                }
                else
                {
                    // delete day
                    var deleted = _clinicRepository.DeleteClinicDay(clinicDay);

                    if (deleted)
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }

            return(HttpNotFound());
        }