/// <summary> /// Creates a joining relationship for a Project /// to an HfhEvent /// </summary> /// <param name="pe">A joining object with the id's of the two objects to join</param> /// <returns>Returns an ErrorCode indicating the result of the db insert</returns> public static ReturnStatus AddProjectToEvent(ProjectEvent pe) { ReturnStatus rs = new ReturnStatus(); VolunteerDbContext db = new VolunteerDbContext(); try { db.eventProjects.Add(pe); db.SaveChanges(); rs.errorCode = ReturnStatus.ALL_CLEAR; } catch { rs.errorCode = ReturnStatus.COULD_NOT_UPDATE_DATABASE; } return(rs); }
/// <summary> /// Deletes the relationship between an HfhEvent /// and a Project /// </summary> /// <param name="vm">An EventAddRemoveProjectVM</param> /// <returns>Returns an errorCode describing the result from the database</returns> public static ReturnStatus RemoveEventProject(EventAddRemoveProjectVM vm) { ReturnStatus rs = new ReturnStatus(); VolunteerDbContext db = new VolunteerDbContext(); try { ProjectEvent pe = db.eventProjects.Where(e => e.project_Id == vm.projectId && e.event_Id == vm.hfhEventId).ToList().FirstOrDefault(); db.eventProjects.Remove(pe); db.SaveChanges(); rs.errorCode = ReturnStatus.ALL_CLEAR; } catch { rs.errorCode = ReturnStatus.COULD_NOT_UPDATE_DATABASE; } return(rs); }