Ejemplo n.º 1
0
        public static List<DiaryEvent> LoadAllAppointmentsInDateRange(double start, double end)
        {
            var fromDate = ConvertFromUnixTimestamp(start);
            var toDate = ConvertFromUnixTimestamp(end);
            using (CalendarContext ent = new CalendarContext())
            {
                var rslt = ent.AppointmentDiaries.Where(s => s.DateTimeScheduled >= fromDate &&
                System.Data.Entity.Core.Objects.EntityFunctions.AddMinutes(s.DateTimeScheduled, s.AppointmentLength) <= 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");
                    rec.EndDateString = item.DateTimeScheduled.AddMinutes(item.AppointmentLength).ToString("s");
                    rec.Title = item.Title + " - " + item.AppointmentLength.ToString() + " mins";
                    rec.StatusString = Enums.GetName((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;
            }

        }
Ejemplo n.º 2
0
        public static List<DiaryEvent> LoadAppointmentSummaryInDateRange(double start, double end)
        {

            var fromDate = ConvertFromUnixTimestamp(start);
            var toDate = ConvertFromUnixTimestamp(end);
            using (CalendarContext ent = new CalendarContext())
            {
                var rslt = ent.AppointmentDiaries.Where(s => s.DateTimeScheduled >= fromDate && System.Data.Entity.Core.Objects.EntityFunctions.AddMinutes(s.DateTimeScheduled, s.AppointmentLength) <= toDate)
                                                        .GroupBy(s => System.Data.Entity.Core.Objects.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;
                    rec.SomeImportantKeyID = -1;
                    string StringDate = string.Format("{0:yyyy-MM-dd}", item.DateTimeScheduled);
                    rec.StartDateString = StringDate + "T00:00:00";
                    rec.EndDateString = StringDate + "T23:59:59";
                    rec.Title = "Booked: " + item.Count.ToString();
                    result.Add(rec);
                    i++;
                }

                return result;
            }

        }
Ejemplo n.º 3
0
        public static void UpdateDiaryEvent(int id, string NewEventStart, string NewEventEnd)
        {

            using (CalendarContext ent = new CalendarContext())
            {
                var rec = ent.AppointmentDiaries.FirstOrDefault(s => s.Id == id);
                if (rec != null)
                {
                    DateTime DateTimeStart = DateTime.Parse(NewEventStart, null, DateTimeStyles.RoundtripKind).ToLocalTime();
                    rec.DateTimeScheduled = DateTimeStart;
                    if (!string.IsNullOrEmpty(NewEventEnd))
                    {
                        TimeSpan span = DateTime.Parse(NewEventEnd, null, DateTimeStyles.RoundtripKind).ToLocalTime() - DateTimeStart;
                        rec.AppointmentLength = Convert.ToInt32(span.TotalMinutes);
                    }
                    ent.SaveChanges();
                }
            }

        }
Ejemplo n.º 4
0
 public static bool CreateNewEvent(string Title, string NewEventDate, string NewEventTime, string NewEventDuration)
 {
     try
     {
         CalendarContext ent = new CalendarContext();
         AppointmentDiary rec = new AppointmentDiary();
         rec.Title = Title;
         rec.DateTimeScheduled = DateTime.ParseExact(NewEventDate + " " + NewEventTime, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);
         rec.AppointmentLength = Int32.Parse(NewEventDuration);
         ent.AppointmentDiaries.Add(rec);
         ent.SaveChanges();
     }
     catch (Exception)
     {
         return false;
     }
     return true;
 }