Beispiel #1
0
 public static List<Event> GetList()
 {
     using (var db = new CalendarContext())
     {
         return db.Events.ToList();
     }
 }
Beispiel #2
0
 public static void DeleteEvent(Event eventToDelete)
 {
     using (var db = new CalendarContext())
     {
         var currentEvent = db.Events.FirstOrDefault(e => e.Id == eventToDelete.Id);
         db.Events.Remove(currentEvent);
         db.SaveChanges();
     }
 }
Beispiel #3
0
        public static Event AddEvent(Event newEvent)
        {
            using (var db = new CalendarContext())
            {
                var book = db.Events.Add(newEvent);
                db.SaveChanges();

                return book;
            }
        }
Beispiel #4
0
 public static bool IsDatesExist(DateTime from, DateTime to, int? eventId)
 {
     using (var db = new CalendarContext())
     {
         return db.Events
             .Where(e => !eventId.HasValue || e.Id != eventId.Value)
             .Any(e => (from >= e.StartDate && from <= e.EndDate)
                                   || (to >= e.StartDate && to <= e.EndDate)
                                   || (from <= e.StartDate && to >= e.EndDate));
     }
 }
Beispiel #5
0
        public static Event UpdateEvent(Event newEvent)
        {
            using (var db = new CalendarContext())
            {
                var currentEvent = db.Events.FirstOrDefault(e => e.Id == newEvent.Id);
                currentEvent.Name = newEvent.Name;
                currentEvent.StartDate = newEvent.StartDate;
                currentEvent.EndDate = newEvent.EndDate;

                db.SaveChanges();
                return currentEvent;
            }
        }