/// <summary> /// Gets a specified study session by Id /// </summary> /// <param name="id">The Id of the study session to get</param> /// <returns>A single study session or null if the specified assignment doesn't exist</returns> public async Task <StudySession> GetStudySessionById(int?id) { return(await StudySessions .Include(s => s.Course) .Include(s => s.StudySessionType) .FirstOrDefaultAsync(s => s.Id == id)); }
/// <summary> /// Sets a study session's status to completed /// </summary> /// <param name="id">Id of the particular study session</param> /// <returns>An integer value representing the number of rows affected in the database, either 1 for success or 0 for fail.</returns> public async Task <int> FinishStudySessionAsync(int id) { var studySession = await GetStudySessionById(id); studySession.IsCompleted = true; StudySessions.Update(studySession); return(await SaveChangesAsync()); }
/// <summary> /// Gets all active or non-active study sessions in the database /// </summary> /// <param name="onlyActive">True = only active study sessions, false = only non-active study sessions</param> /// <returns>An Iqueryable object of type StudySession</returns> public IQueryable <StudySession> GetStudySessions(bool onlyActive) { IQueryable <StudySession> studySessions = StudySessions .Include(sa => sa.StudySessionType) .Include(sa => sa.Course); if (onlyActive) { studySessions = studySessions.Where(sa => DateTime.Now.CompareTo(sa.GetStudySessionEnd()) < 0 && sa.IsCompleted == false); } return(studySessions); }