public PagedList<PercentageGraphData> GetPercentageGraphsForLecturer(int lecturerId, GetPagedListParams parms, int secretaryId) { AuthorizationHelper.ValidateLecturerAccess(Context, lecturerId); parms.SortExpression = "Date"; return GetPercentageGraphDataForLecturerQuery(lecturerId, secretaryId).ApplyPaging(parms); }
public PagedList<PercentageGraphData> GetPercentageGraphs(int userId, GetPagedListParams parms) { var groupId = 0; if (parms.Filters.ContainsKey("groupId")) { int.TryParse(parms.Filters["groupId"], out groupId); } var user = Context.Users.Include(x => x.Student.Group).Include(x => x.Lecturer).Single(x => x.Id == userId); var isLecturer = user.Lecturer != null; var isStudent = user.Student != null; var isSecretary = isLecturer && user.Lecturer.IsSecretary; if (isLecturer && !isSecretary) { return GetPercentageGraphsForLecturer(userId, parms, groupId); } var secretaryId = isStudent ? user.Student.Group.SecretaryId : userId; return Context.DiplomPercentagesGraphs .AsNoTracking() .Where(x => x.LecturerId == secretaryId) .Select(ToPercentageDataPlain) .ApplyPaging(parms); }
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext) { var nvc = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.Query); var model = new GetPagedListParams { PageSize = int.Parse(nvc["count"]), Page = int.Parse(nvc["page"]), SortExpression = "Id" }; var sortingKey = nvc.AllKeys.FirstOrDefault(x => x.StartsWith("sorting[")); if (sortingKey != null) { model.SortExpression = sortingKey.RemoveStringEntries("sorting[", "]") + " " + nvc[sortingKey]; } model.Filters = nvc.AllKeys.Where(x => x.StartsWith("filter[")) .ToDictionary(x => x.RemoveStringEntries("filter[", "]"), y => nvc[y]); if (nvc.AllKeys.Contains("filter")) { model.Filters = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(nvc["filter"]); } bindingContext.Model = model; return true; }
public List<PercentageGraphData> GetPercentageGraphsForLecturerAll(int userId, GetPagedListParams parms) { var secretaryId = 0; if (parms.Filters.ContainsKey("secretaryId")) { int.TryParse(parms.Filters["secretaryId"], out secretaryId); } var subjectId = 0; if (parms.Filters.ContainsKey("subjectId")) { int.TryParse(parms.Filters["subjectId"], out subjectId); } var isStudent = AuthorizationHelper.IsStudent(Context, userId); var isLecturer = AuthorizationHelper.IsLecturer(Context, userId); var isLecturerSecretary = isLecturer && Context.Lecturers.Single(x => x.Id == userId).IsSecretary; secretaryId = userId; if (isStudent) { secretaryId = Context.Users.Where(x => x.Id == userId) .Select(x => x.Student.AssignedCourseProjects.FirstOrDefault().CourseProject.LecturerId) .Single() ?? 0; } return GetPercentageGraphDataForLecturerQuery(isLecturer || isStudent ? 0 : userId, secretaryId, subjectId) .Where(x => x.Date >= _currentAcademicYearStartDate && x.Date < _currentAcademicYearEndDate) .OrderBy(x => x.Date) .ToList(); }
public PagedList<PercentageGraphData> GetPercentageGraphs(int userId, GetPagedListParams parms) { var groupId = 0; if (parms.Filters.ContainsKey("groupId")) { int.TryParse(parms.Filters["groupId"], out groupId); } var subjectId = 0; if (parms.Filters.ContainsKey("subjectId")) { int.TryParse(parms.Filters["subjectId"], out subjectId); } var user = Context.Users.Include(x => x.Student.Group).Include(x => x.Lecturer).Single(x => x.Id == userId); var isLecturer = user.Lecturer != null; var isStudent = user.Student != null; var isSecretary = isLecturer && user.Lecturer.IsSecretary; var secretaryId = isStudent ? user.Student.Group.SecretaryId : userId; if (isStudent) { secretaryId = Context.Users.Where(x => x.Id == userId) .Select(x => x.Student.AssignedCourseProjects.FirstOrDefault().CourseProject.LecturerId) .Single() ?? 0; } return Context.CoursePercentagesGraphs .AsNoTracking() .Where(x => x.LecturerId == secretaryId) .Where(x => x.SubjectId == subjectId) .Select(ToPercentageDataPlain) .ApplyPaging(parms); }
public PagedList<CourseProjectData> GetProjects(int userId, GetPagedListParams parms) { var subjectId = int.Parse(parms.Filters["subjectId"]); var searchString = parms.Filters["searchString"]; var query = Context.CourseProjects.AsNoTracking() .Include(x => x.Lecturer) .Include(x => x.AssignedCourseProjects.Select(asp => asp.Student.Group)) .Include(x=>x.Subject); var user = Context.Users.Include(x => x.Student).Include(x => x.Lecturer).SingleOrDefault(x => x.Id == userId); if (user != null && user.Lecturer != null) { query = query.Where(x => x.LecturerId == userId).Where(x => x.SubjectId == subjectId); } if (user != null && user.Student != null) { query = query.Where(x => x.CourseProjectGroups.Any(dpg => dpg.GroupId == user.Student.GroupId)).Where(x => x.SubjectId == subjectId); } if (searchString.Length > 0) { var courseProjects = from cp in query let acp = cp.AssignedCourseProjects.FirstOrDefault() where acp.Student.LastName.Contains(searchString) || cp.Theme.Contains(searchString) || acp.Student.Group.Name.Contains(searchString) select new CourseProjectData { Id = cp.CourseProjectId, Theme = cp.Theme, Lecturer = cp.Lecturer != null ? cp.Lecturer.LastName + " " + cp.Lecturer.FirstName + " " + cp.Lecturer.MiddleName : null, Student = acp.Student != null ? acp.Student.LastName + " " + acp.Student.FirstName + " " + acp.Student.MiddleName : null, StudentId = acp.StudentId, Group = acp.Student.Group.Name, ApproveDate = acp.ApproveDate }; return courseProjects.ApplyPaging(parms); } else { var courseProjects = from cp in query let acp = cp.AssignedCourseProjects.FirstOrDefault() select new CourseProjectData { Id = cp.CourseProjectId, Theme = cp.Theme, Lecturer = cp.Lecturer != null ? cp.Lecturer.LastName + " " + cp.Lecturer.FirstName + " " + cp.Lecturer.MiddleName : null, Student = acp.Student != null ? acp.Student.LastName + " " + acp.Student.FirstName + " " + acp.Student.MiddleName : null, StudentId = acp.StudentId, Group = acp.Student.Group.Name, ApproveDate = acp.ApproveDate }; return courseProjects.ApplyPaging(parms); } }
public PagedList<DiplomProjectData> GetProjects(int userId, GetPagedListParams parms) { var query = Context.DiplomProjects.AsNoTracking() .Include(x => x.Lecturer) .Include(x => x.AssignedDiplomProjects.Select(asp => asp.Student.Group)); var user = Context.Users.Include(x => x.Student).Include(x => x.Lecturer).SingleOrDefault(x => x.Id == userId); if (user != null && user.Lecturer != null && !user.Lecturer.IsSecretary) { query = query.Where(x => x.LecturerId == userId); } if (user != null && user.Lecturer != null && user.Lecturer.IsSecretary) { query = query.Where(x => x.AssignedDiplomProjects.Any()); } if (user != null && user.Student != null) { query = query.Where(x => x.DiplomProjectGroups.Any(dpg => dpg.GroupId == user.Student.GroupId)); } var diplomProjects = from dp in query let adp = dp.AssignedDiplomProjects.FirstOrDefault() select new DiplomProjectData { Id = dp.DiplomProjectId, Theme = dp.Theme, Lecturer = dp.Lecturer != null ? dp.Lecturer.LastName + " " + dp.Lecturer.FirstName + " " + dp.Lecturer.MiddleName : null, Student = adp.Student != null ? adp.Student.LastName + " " + adp.Student.FirstName + " " + adp.Student.MiddleName : null, StudentId = adp.StudentId, Group = adp.Student.Group.Name, ApproveDate = adp.ApproveDate }; return diplomProjects.ApplyPaging(parms); }
public PagedList<StudentData> GetStudentsByCourseProjectId(GetPagedListParams parms) { if (!parms.Filters.ContainsKey("courseProjectId")) { throw new ApplicationException("coursePorjectId can't be empty!"); } parms.SortExpression = "Group, Name"; var courseProjectId = int.Parse(parms.Filters["courseProjectId"]); return Context.Students .Include(x => x.Group.CourseProjectGroups) .Where(x => x.Group.CourseProjectGroups.Any(dpg => dpg.CourseProjectId == courseProjectId)) .Where(x => !x.AssignedCourseProjects.Any()) .Select(s => new StudentData { Id = s.Id, Name = s.LastName + " " + s.FirstName + " " + s.MiddleName, //todo Group = s.Group.Name }).ApplyPaging(parms); }
public PagedList<StudentData> GetGraduateStudentsForUser(int userId, int subjectId, GetPagedListParams parms, bool getBySecretaryForStudent = true) { var secretaryId = 0; if (parms.Filters.ContainsKey("secretaryId")) { int.TryParse(parms.Filters["secretaryId"], out secretaryId); } var isStudent = AuthorizationHelper.IsStudent(Context, userId); var isLecturer = AuthorizationHelper.IsLecturer(Context, userId); var isLecturerSecretary = isLecturer && Context.Lecturers.Single(x => x.Id == userId).IsSecretary; secretaryId = isLecturerSecretary ? userId : secretaryId; if (isStudent) { if (getBySecretaryForStudent) { secretaryId = Context.Users.Where(x => x.Id == userId).Select(x => x.Student.Group.SecretaryId).Single() ?? 0; } else { userId = Context.Users.Where(x => x.Id == userId) .Select(x => x.Student.AssignedCourseProjects.FirstOrDefault().CourseProject.LecturerId) .Single() ?? 0; } } if (string.IsNullOrWhiteSpace(parms.SortExpression) || parms.SortExpression == "Id") { parms.SortExpression = "Name"; } var query = Context.Students .Where(x => isLecturerSecretary || (isStudent && getBySecretaryForStudent) || x.AssignedCourseProjects.Any(asd => asd.CourseProject.LecturerId == userId && asd.CourseProject.SubjectId == subjectId)) .Where(x => secretaryId == 0 || x.Group.SecretaryId == secretaryId) .Where(x => x.AssignedCourseProjects.Any(a => a.CourseProject.SubjectId == subjectId)); return (from s in query let lecturer = s.AssignedCourseProjects.FirstOrDefault().CourseProject.Lecturer select new StudentData { Id = s.Id, Name = s.LastName + " " + s.FirstName + " " + s.MiddleName, //todo Mark = s.AssignedCourseProjects.FirstOrDefault().Mark, AssignedCourseProjectId = s.AssignedCourseProjects.FirstOrDefault().Id, Lecturer = lecturer.LastName + " " + lecturer.FirstName + " " + lecturer.MiddleName, //todo Group = s.Group.Name, PercentageResults = s.CoursePercentagesResults.Select(pr => new PercentageResultData { Id = pr.Id, PercentageGraphId = pr.CoursePercentagesGraphId, StudentId = pr.StudentId, Mark = pr.Mark, Comment = pr.Comments }), CourseProjectConsultationMarks = s.CourseProjectConsultationMarks.Select(cm => new CourseProjectConsultationMarkData { Id = cm.Id, ConsultationDateId = cm.ConsultationDateId, StudentId = cm.StudentId, Mark = cm.Mark, Comments = cm.Comments }) }).ApplyPaging(parms); }