Exemplo n.º 1
0
        public ActionResult EditClinicDay(int id)
        {
            // get clinic day to edit
            var clinicDay = _clinicRepository.GetClinicDay(id);

            if (clinicDay != null)
            {
                var sTime  = clinicDay.OpenTime.Split(new string[] { ":", " " }, StringSplitOptions.RemoveEmptyEntries);
                var sHours = sTime[0];
                var sMins  = sTime[1];
                var sAMPM  = sTime[2];

                var eTime  = clinicDay.CloseTime.Split(new string[] { ":", " " }, StringSplitOptions.RemoveEmptyEntries);
                var eHours = eTime[0];
                var eMins  = eTime[1];
                var eAMPM  = eTime[2];

                // map to view model
                var editClinicdayViewModel = new EditClinicDayViewModel()
                {
                    Id            = clinicDay.Id,
                    Day           = clinicDay.Day,
                    StartTimeHour = sHours,
                    StartTimeMin  = sMins,
                    StartAMPM     = sAMPM,
                    EndTimeHour   = eHours,
                    EndTimeMin    = eMins,
                    EndAMPM       = eAMPM,
                    ClinicId      = clinicDay.ClinicId,
                    Hours         = GetHoursList(),
                    Minutes       = GetMinutesList(),
                    AMPM          = GetAMPMList()
                };

                return(View(editClinicdayViewModel));
            }

            return(HttpNotFound());
        }
Exemplo n.º 2
0
        public ActionResult EditClinicDay(EditClinicDayViewModel editClinicDay)
        {
            if (ModelState.IsValid)
            {
                var day = editClinicDay.Day;

                var openTime = editClinicDay.StartTimeHour + ":"
                               + editClinicDay.StartTimeMin + " "
                               + editClinicDay.StartAMPM;
                var closeTime = editClinicDay.EndTimeHour + ":"
                                + editClinicDay.EndTimeMin + " "
                                + editClinicDay.EndAMPM;

                // check if start time is not before end time
                var startTime = Convert.ToDateTime(openTime);
                var endTime   = Convert.ToDateTime(closeTime);

                if (startTime.Hour < endTime.Hour)
                {
                    ModelState.AddModelError("CustomError", "end time cannot be before start time!");
                    var model = new EditClinicDayViewModel()
                    {
                        Id            = editClinicDay.Id,
                        Day           = editClinicDay.Day,
                        StartTimeHour = editClinicDay.StartTimeHour,
                        StartTimeMin  = editClinicDay.StartTimeMin,
                        StartAMPM     = editClinicDay.StartAMPM,

                        EndTimeHour = editClinicDay.EndTimeHour,
                        EndTimeMin  = editClinicDay.EndTimeMin,
                        EndAMPM     = editClinicDay.EndAMPM,
                        ClinicId    = editClinicDay.ClinicId,
                        Hours       = GetHoursList(),
                        Minutes     = GetMinutesList(),
                        AMPM        = GetAMPMList()
                    };

                    return(View(model));
                }
                else
                {
                    // create clinic day
                    var clinicDay = new ClinicDay()
                    {
                        Id        = editClinicDay.Id,
                        Day       = day,
                        OpenTime  = openTime,
                        CloseTime = closeTime,
                        ClinicId  = editClinicDay.ClinicId
                    };

                    // update clinic day
                    var updated = _clinicRepository.UpdateClinicDay(clinicDay);
                    if (updated)
                    {
                        return(RedirectToAction("Index"));
                    }
                }

                return(HttpNotFound("Unale to save day. Something went wrong while saving"));
            }
            return(HttpNotFound());
        }