Beispiel #1
0
        public static List <DiaryEvent> LoadAppointmentSummaryInDateRange(double start, double end)
        {
            var fromDate = ConvertFromUnixTimestamp(start);
            var toDate   = ConvertFromUnixTimestamp(end);

            using (var ent = new MyDbContext())
            {
                var rslt = ent.AppointmentDiaries.Where(s => s.DateTimeScheduled >= fromDate && EntityFunctions.AddMinutes(s.DateTimeScheduled, s.AppointmentLength) <= toDate)
                           .GroupBy(s => EntityFunctions.TruncateTime(s.DateTimeScheduled))
                           .Select(x => new { DateTimeScheduled = x.Key, Count = x.Count() });

                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();
                    result.Add(rec);
                    i++;
                }

                return(result);
            }
        }
Beispiel #2
0
        public static List <DiaryEvent> LoadAllAppointmentsInDateRange(double start, double end, string userid)
        {
            var isAdmin = false;

            if (ClaimsPrincipal.Current != null)
            {
                isAdmin = ClaimsPrincipal.Current.IsInRole("Admin");
            }
            var fromDate = ConvertFromUnixTimestamp(start);
            var toDate   = ConvertFromUnixTimestamp(end);

            toDate = toDate.AddHours(2);
            using (var ent = new MyDbContext())
            {
                var rslt     = ent.AppointmentDiaries.Where(s => s.DateTimeScheduled >= fromDate && EntityFunctions.AddMinutes(s.DateTimeScheduled, s.AppointmentLength) <= toDate).ToArray();
                var userRslt = ent.UserSubscriptions.Where(s => s.UserId == userid && s.Pending != 1).Select(d => d.AppointmentDairyId).ToArray();
                var result   = new List <DiaryEvent>();
                foreach (var item in rslt)
                {
                    var rec = new DiaryEvent
                    {
                        ID = item.Id,
                        StartDateString = item.DateTimeScheduled.ToString("s"),
                        EndDateString   = item.DateTimeScheduled.AddMinutes(item.AppointmentLength + 30).ToString("s"),
                        Title           = item.Title
                    };

                    // "s" is a preset format that outputs as: "2009-02-27T12:12:22"
                    // field AppointmentLength is in minutes

                    //when cursist has booked, show event in orange
                    if (userRslt.Contains(item.Id))
                    {
                        rec.StatusString       = Enums.GetName((AppointmentStatus)1);
                        rec.SomeImportantKeyID = item.DateTimeScheduled <= DateTime.Now.AddDays(1) ? 667 : 666;
                    }
                    else
                    {
                        rec.OriginalKeyID = item.StatusEnum;
                        //when no admin (so cursist) & 24hours before event, show as unavailable = gray
                        if (item.DateTimeScheduled <= DateTime.Now.AddDays(1) && !isAdmin)
                        {
                            rec.StatusString       = Enums.GetName((AppointmentStatus)3);
                            rec.SomeImportantKeyID = 3;
                        }
                        else
                        {
                            //check when cursus is fully booked & the current cursist has not booked yet, show in red:
                            var results = ent.UserSubscriptions.Count(w => w.AppointmentDairyId == item.Id && w.Pending != 1);
                            if (results >= 10)
                            {
                                rec.StatusString       = Enums.GetName((AppointmentStatus)4);
                                rec.SomeImportantKeyID = 4;
                                rec.Title = "Les volzet";
                            }
                            //everything else: show as available or holiday
                            else
                            {
                                rec.StatusString       = Enums.GetName((AppointmentStatus)item.StatusEnum);
                                rec.SomeImportantKeyID = item.StatusEnum;
                            }
                        }
                    }

                    rec.StatusColor = Enums.GetEnumDescription <AppointmentStatus>(rec.StatusString);
                    var 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);
            }
        }