public ActionResult AddClinicDays(ClinicDayViewModel clinicDay) { if (ModelState.IsValid) { var day = clinicDay.Day; var openTime = clinicDay.StartTimeHour + ":" + clinicDay.StartTimeMin + " " + clinicDay.StartAMPM; var closeTime = clinicDay.EndTimeHour + ":" + clinicDay.EndTimeMin + " " + clinicDay.EndAMPM; var addClinicDay = new ClinicDay() { Day = day, OpenTime = openTime, CloseTime = closeTime, ClinicId = clinicDay.ClinicId }; // add clinic day var created = _clinicRepository.AddClinicDay(addClinicDay); if (created) { return(RedirectToAction("Index")); } return(HttpNotFound("Unale to save day. Something went wrong while saving")); } return(View(clinicDay)); }
public ActionResult AddClinicDays(int id) { // get existing days var existingDays = _clinicRepository.GetClinicDays(id); IEnumerable <SelectListItem> existingDaysList = existingDays.Select(s => new SelectListItem { Text = s.ToString(), Value = ((int)s).ToString() }); // convert enum to selectListItem var enumList = Enum.GetValues(typeof(WeekDays)).Cast <WeekDays>().Select(s => new SelectListItem { Text = s.ToString(), Value = ((int)s).ToString() }); // list to filter existing days List <SelectListItem> remainingDaysList = new List <SelectListItem>(); // loop through to filter existing days foreach (var day in enumList) { if (!existingDaysList.Any(s => s.Value == day.Value)) { remainingDaysList.Add(day); } } // reconstruct IEnumerable select list to display in view IEnumerable <SelectListItem> remainingDays = remainingDaysList.Select(s => new SelectListItem { Text = s.Text, Value = s.Value }); // create clinic day var clinicDays = new ClinicDayViewModel() { // copy remaining days RemainingDays = remainingDays, ClinicId = id, Hours = new List <SelectListItem> { new SelectListItem { Value = "1", Text = "01" }, new SelectListItem { Value = "2", Text = "02" }, new SelectListItem { Value = "3", Text = "03" }, new SelectListItem { Value = "4", Text = "04" }, new SelectListItem { Value = "5", Text = "05" }, new SelectListItem { Value = "6", Text = "06" }, new SelectListItem { Value = "7", Text = "07" }, new SelectListItem { Value = "8", Text = "08" }, new SelectListItem { Value = "9", Text = "09" }, new SelectListItem { Value = "10", Text = "10" }, new SelectListItem { Value = "11", Text = "11" }, new SelectListItem { Value = "12", Text = "12" } }, Minutes = new List <SelectListItem> { new SelectListItem { Value = "00", Text = "00" }, new SelectListItem { Value = "15", Text = "15" }, new SelectListItem { Value = "30", Text = "30" }, new SelectListItem { Value = "45", Text = "45" } }, AMPM = new List <SelectListItem> { new SelectListItem { Value = "AM", Text = "AM" }, new SelectListItem { Value = "PM", Text = "PM" } } }; return(View(clinicDays)); }