示例#1
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();
     }
 }
示例#2
0
        public static Event AddEvent(Event newEvent)
        {
            using (var db = new CalendarContext())
            {
                var book = db.Events.Add(newEvent);
                db.SaveChanges();

                return book;
            }
        }
示例#3
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;
            }
        }