public static ReturnStatus CreateEvent(HfhEvent hfhEvent) { ReturnStatus rs = new ReturnStatus(); try { VolunteerDbContext db = new VolunteerDbContext(); db.hfhEvents.Add(hfhEvent); db.SaveChanges(); rs.errorCode = ReturnStatus.ALL_CLEAR; } catch { rs.errorCode = ReturnStatus.COULD_NOT_UPDATE_DATABASE; } return(rs); }
/// <summary> /// Edits the event with new values. /// </summary> /// <param name="event">The event object with new values.</param> public static ReturnStatus EditHfhEvent(HfhEvent hfhEvent) { ReturnStatus st = new ReturnStatus(); st.data = null; try { VolunteerDbContext db = new VolunteerDbContext(); db.Entry(hfhEvent).State = EntityState.Modified; db.SaveChanges(); st.errorCode = ReturnStatus.ALL_CLEAR; return(st); } catch (Exception e) { st.errorCode = ReturnStatus.COULD_NOT_CONNECT_TO_DATABASE; st.errorMessage = e.ToString(); return(st); } }
/// <summary> /// Deletes an HfhEvent and any relationships /// it has to Projects from the database /// </summary> /// <param name="id"></param> /// <returns>ErrorCode describing result of delete action</returns> public static ReturnStatus DeleteEvent(int id) { ReturnStatus rs = new ReturnStatus(); try { VolunteerDbContext db = new VolunteerDbContext(); // get rid of all foreign key relationships first var joinsToRemove = db.eventProjects.Where(ep => ep.event_Id == id); db.eventProjects.RemoveRange(joinsToRemove); db.SaveChanges(); // remove the event itself HfhEvent hfhEvent = db.hfhEvents.Find(id); db.hfhEvents.Remove(hfhEvent); db.SaveChanges(); rs.errorCode = ReturnStatus.ALL_CLEAR; } catch { rs.errorCode = ReturnStatus.COULD_NOT_UPDATE_DATABASE; } return(rs); }