Exemplo n.º 1
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();
                }
            }

        }
Exemplo n.º 2
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;
 }