public ActionResult CreateAppointment(int id, int?day, int?month, int?year)
        {
            if (Session["Authen"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }


            if (month == null && year == null)
            {
                day   = DateTime.Now.Day;
                month = DateTime.Now.Month;
                year  = DateTime.Now.Year;
            }

            CheckExitsTimeSlot(day, month, year);

            CreateAppointmentViewModel result = new CreateAppointmentViewModel
            {
                date       = new DateTime(year.Value, month.Value, day.Value),
                member     = _MemberRepo.GetByID(id),
                pets       = _PetRepo.GetByMemberID(id),
                services   = _ServiceRepo.GetAll(),
                timeblocks = _TimeSlotRepo.GetListByDate(day.Value, month.Value, year.Value)
            };

            return(View(result));
        }
Esempio n. 2
0
        /* public ActionResult UpcomingAppointment(int? memberId)
         * {
         *   DateTime today = DateTime.Now;
         *
         *   var appointmentList = _AppRepo.GetByMemberIdAndDayAndMonthAndYearNoStatus(memberId.Value, today.Year, today.Month, today.Day);
         *
         *   var a = appointmentList.Select(s => new AppointmentViewModel
         *   {
         *       appointmentId = s.id,
         *       start = s.startTime,
         *       end = s.endTime,
         *       petName = s.Pet.name,
         *       petSpecie = s.Pet.Specie.name,
         *       service = s.VAService.description,
         *       detail = s.detail,
         *       suggestion = s.suggestion
         *
         *   });
         *
         *   return Json(JsonConvert.SerializeObject(a), JsonRequestBehavior.AllowGet);
         * }
         */
        public ActionResult CheckTimetble(int?day, int?month, int?year)
        {
            if (month == null)
            {
                month = DateTime.Now.Month;
            }
            if (year == null)
            {
                year = DateTime.Now.Year;
            }
            if (day == null)
            {
                day = DateTime.Now.Day;
            }
            // Check if the system already have that day time table -- if not, create one//
            TimeSpan start = new TimeSpan(09, 30, 0);
            TimeSpan end   = new TimeSpan(21, 00, 0);
            DateTime today = new DateTime(year.Value, month.Value, day.Value);

            TimeSlot checkExits = _TimeSlotRepo.GetByDate(day.Value, month.Value, year.Value);

            int      offset     = today.DayOfWeek - DayOfWeek.Monday;
            DateTime lastMonday = today.AddDays(-offset);
            DateTime endWeek    = lastMonday.AddDays(6);

            if (checkExits == null)
            {
                //Loop for this week
                while (lastMonday <= endWeek)
                {
                    //Start from monday -> sunday

                    DateTime dt = new DateTime(lastMonday.Year, lastMonday.Month, lastMonday.Day);
                    //Loop for hour in day

                    DateTime startTime = new DateTime(dt.Year, dt.Month, dt.Day) + start;
                    DateTime endTime   = new DateTime(dt.Year, dt.Month, dt.Day) + end;
                    var      hours     = new List <DateTime>();
                    hours.Add(startTime);
                    var next = new DateTime(startTime.Year, startTime.Month, startTime.Day,
                                            startTime.Hour, startTime.Minute, 0, startTime.Kind);
                    while ((next = next.AddHours(0.5)) < endTime)
                    {
                        hours.Add(next);
                    }
                    hours.Add(endTime);

                    foreach (var hour in hours)
                    {
                        TimeSlot timeblock = new TimeSlot();
                        timeblock.startTime    = hour;
                        timeblock.endTime      = hour.AddHours(0.5);
                        timeblock.numberofCase = 0;
                        timeblock.status       = "Free";
                        _TimeSlotRepo.Add(timeblock);
                    }
                    lastMonday = lastMonday.AddDays(1);
                }
            }

            var timetable = _TimeSlotRepo.GetListByDate(day.Value, month.Value, year.Value);

            var t = timetable.Select(s => new TimeSlot
            {
                id        = s.id,
                startTime = s.startTime,
                endTime   = s.endTime,
                status    = s.status
            });

            return(Json(JsonConvert.SerializeObject(t), JsonRequestBehavior.AllowGet));
        }