public static List <DiaryEvent> LoadAllAppointmentsInDateRange(double start, double end)
        {
            var fromDate = ConvertFromUnixTimestamp(start);
            var toDate   = ConvertFromUnixTimestamp(end);

            using (ApplicationDbContext ent = new ApplicationDbContext())
            {
                //var rslt = ent.AppointmentDiary.Where(s => s.DateTimeScheduled >= fromDate && System.Data.Objects.EntityFunctions.AddMinutes(s.DateTimeScheduled, s.AppointmentLength) <= toDate);
                var rslt = ent.SchedulingDiarys.Where(s => s.DateTimeScheduled >= fromDate && s.DateTimeScheduled <= toDate);

                List <DiaryEvent> result = new List <DiaryEvent>();
                foreach (var item in rslt)
                {
                    DiaryEvent rec = new DiaryEvent();

                    rec.ID = item.ID;
                    //   rec.SomeImportantKeyID = item.SomeImportantKey;
                    rec.StartDateString = item.DateTimeScheduled.ToString();                  // "s" is a preset format that outputs as: "2009-02-27T12:12:22"
                    rec.EndDateString   = item.DateTimeScheduled.AddMinutes(0).ToString("s"); // field AppointmentLength is in minutes
                    // rec.Title = item.Title + " - " + item.AppointmentLength.ToString() + " mins";

                    rec.Title        = (item.StartTime + " " + item.StartSlot + " To " + item.EndTime + " " + item.EndSlot).ToString();
                    rec.StatusString = Enums.GetName <AppointmentStatus>((AppointmentStatus)item.StatusENUM);
                    rec.StatusColor  = Enums.GetEnumDescription <AppointmentStatus>(rec.StatusString);
                    string ColorCode = rec.StatusColor.Substring(0, rec.StatusColor.IndexOf(":"));
                    rec.ClassName   = rec.StatusColor.Substring(rec.StatusColor.IndexOf(":") + 1, rec.StatusColor.Length - ColorCode.Length - 1);
                    rec.StatusColor = ColorCode;
                    result.Add(rec);
                }

                return(result);
            }
        }
        public static List <DiaryEvent> LoadAppointmentSummaryInDateRange(double start, double end)
        {
            var fromDate = ConvertFromUnixTimestamp(start);
            var toDate   = ConvertFromUnixTimestamp(end);

            using (ApplicationDbContext ent = new ApplicationDbContext())
            {
                //var rslt = ent.AppointmentDiary.Where(s => s.DateTimeScheduled >= fromDate && System.Data.Objects.EntityFunctions.AddMinutes(s.DateTimeScheduled, s.AppointmentLength) <= toDate)
                //                                        .GroupBy(s => System.Data.Objects.EntityFunctions.TruncateTime(s.DateTimeScheduled))
                //                                        .Select(x => new { DateTimeScheduled = x.Key, Count = x.Count() });

                var rslt = ent.SchedulingDiarys.Where(s => s.DateTimeScheduled >= fromDate && s.DateTimeScheduled <= toDate);

                List <DiaryEvent> result = new List <DiaryEvent>();
                int i = 0;
                foreach (var item in rslt)
                {
                    DiaryEvent rec = new DiaryEvent();
                    //rec.ID = i; //we dont link this back to anything as its a group summary but the fullcalendar needs unique IDs for each event item (unless its a repeating event)
                    //rec.SomeImportantKeyID = -1;
                    //string StringDate = string.Format("{0:yyyy-MM-dd}", item.DateTimeScheduled);
                    //rec.StartDateString = StringDate + "T00:00:00"; //ISO 8601 format
                    //rec.EndDateString = StringDate + "T23:59:59";
                    ////  rec.Title = "Booked: " + item.Count.ToString();
                    //rec.Title = "Booked: ";
                    //result.Add(rec);
                    //i++;

                    rec.ID = item.ID;
                    //   rec.SomeImportantKeyID = item.SomeImportantKey;
                    rec.StartDateString = item.DateTimeScheduled.ToString();                  // "s" is a preset format that outputs as: "2009-02-27T12:12:22"
                    rec.EndDateString   = item.DateTimeScheduled.AddMinutes(0).ToString("s"); // field AppointmentLength is in minutes
                    // rec.Title = item.Title + " - " + item.AppointmentLength.ToString() + " mins";

                    rec.Title        = (item.StartTime + " " + item.StartSlot + " To " + item.EndTime + " " + item.EndSlot).ToString();
                    rec.StatusString = Enums.GetName <AppointmentStatus>((AppointmentStatus)item.StatusENUM);
                    rec.StatusColor  = Enums.GetEnumDescription <AppointmentStatus>(rec.StatusString);
                    string ColorCode = rec.StatusColor.Substring(0, rec.StatusColor.IndexOf(":"));
                    rec.ClassName   = rec.StatusColor.Substring(rec.StatusColor.IndexOf(":") + 1, rec.StatusColor.Length - ColorCode.Length - 1);
                    rec.StatusColor = ColorCode;
                    result.Add(rec);
                }

                return(result);
            }
        }