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