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 IActionResult Get([ModelBinder] GetPagedListParams parms) { var subjectId = 0; if (parms.Filters.ContainsKey("subjectId")) { subjectId = int.Parse(parms.Filters["subjectId"]); } var groupId = 0; if (parms.Filters.ContainsKey("groupId")) { groupId = int.Parse(parms.Filters["groupId"]); } var result = new { Students = CpManagementService.GetGraduateStudentsForGroup(/*todo #auth WebSecurity.CurrentUserId*/ 2, groupId, subjectId, parms, false), PercentageGraphs = PercentageService.GetPercentageGraphsForLecturerAll(/*todo #auth WebSecurity.CurrentUserId*/ 2, parms) }; return(Ok(result)); }
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 IActionResult Get([ModelBinder] GetPagedListParams parms) { var lecturerId = /*todo #auth WebSecurity.CurrentUserId*/ 2; if (parms.Filters.ContainsKey("lecturerId")) { lecturerId = int.Parse(parms.Filters["lecturerId"]); } var subjectId = 0; if (parms.Filters.ContainsKey("subjectId")) { subjectId = int.Parse(parms.Filters["subjectId"]); } var groupId = 0; if (parms.Filters.ContainsKey("groupId")) { groupId = int.Parse(parms.Filters["groupId"]); } var result = new { Students = CpManagementService.GetGraduateStudentsForGroup(lecturerId, groupId, subjectId, parms, false), CourseProjectConsultationDates = PercentageService.GetConsultationDatesForUser(lecturerId, subjectId) }; return(Ok(result)); }
public object Get([System.Web.Http.ModelBinding.ModelBinder] GetPagedListParams parms) { return(new { Students = DpManagementService.GetGraduateStudentsForUser(WebSecurity.CurrentUserId, parms), PercentageGraphs = PercentageService.GetPercentageGraphsForLecturerAll(WebSecurity.CurrentUserId, parms) }); }
public IActionResult Get([ModelBinder] GetPagedListParams parms) { var result = new { Students = DpManagementService.GetGraduateStudentsForUser(/*todo #auth WebSecurity.CurrentUserId*/ 2, parms), PercentageGraphs = PercentageService.GetPercentageGraphsForLecturerAll(/*todo #auth WebSecurity.CurrentUserId*/ 2, parms) }; return(Ok(result)); }
public object Get([System.Web.Http.ModelBinding.ModelBinder] GetPagedListParams parms) { var subjectId = 0; if (parms.Filters.ContainsKey("subjectId")) { subjectId = int.Parse(parms.Filters["subjectId"]); } return(new { Students = CpManagementService.GetGraduateStudentsForUser(WebSecurity.CurrentUserId, subjectId, parms), PercentageGraphs = PercentageService.GetPercentageGraphsForLecturerAll(WebSecurity.CurrentUserId, parms) }); }
public static PagedList <T> ApplyPaging <T>(this IQueryable <T> query, GetPagedListParams parms) { return (new PagedList <T> { Total = query.Count(), Items = query .OrderBy(parms.SortExpression) .Skip((parms.Page - 1) * parms.PageSize) .Take(parms.PageSize) .ToList() }); }
public object Get([System.Web.Http.ModelBinding.ModelBinder] GetPagedListParams parms) { var lecturerId = WebSecurity.CurrentUserId; if (parms.Filters.ContainsKey("lecturerId")) { lecturerId = int.Parse(parms.Filters["lecturerId"]); } return(new { Students = DpManagementService.GetGraduateStudentsForUser(lecturerId, parms, false), DipomProjectConsultationDates = PercentageService.GetConsultationDatesForUser(lecturerId) }); }
public static PagedList <T> ApplyPaging <T>(this IQueryable <T> query, GetPagedListParams parms) { return (new PagedList <T>()); // todo # //{ // Total = query.Count(), // Items = // query // .OrderBy(parms.SortExpression) // .Skip((parms.Page - 1) * parms.PageSize) // .Take(parms.PageSize) // .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; /* if (isLecturer && !isSecretary) * { * return GetPercentageGraphsForLecturer(userId, parms, groupId); * } */ 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 <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 <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> GetStudentsByDiplomProjectId(GetPagedListParams parms) { if (!parms.Filters.ContainsKey("diplomProjectId")) { throw new ApplicationException("diplomPorjectId can't be empty!"); } parms.SortExpression = "Group, Name"; var diplomProjectId = int.Parse(parms.Filters["diplomProjectId"]); return(Context.GetGraduateStudents() .Include(x => x.Group.DiplomProjectGroups) .Where(x => x.Group.DiplomProjectGroups.Any(dpg => dpg.DiplomProjectId == diplomProjectId)) .Where(x => !x.AssignedDiplomProjects.Any()) .Where(x => x.Confirmed == null || x.Confirmed.Value) .Select(s => new StudentData { Id = s.Id, Name = s.LastName + " " + s.FirstName + " " + s.MiddleName, //todo Group = s.Group.Name }).ApplyPaging(parms)); }
public PagedList <CourseProjectData> GetProjects(int userId, GetPagedListParams parms) { var subjectId = int.Parse(parms.Filters["subjectId"]); 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); } 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 <PercentageGraphData> Get([ModelBinder] GetPagedListParams parms) { return(PercentageService.GetPercentageGraphs(WebSecurity.CurrentUserId, parms)); }
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 = /*isLecturerSecretary ?*/ userId /* : secretaryId*/; if (isStudent) { secretaryId = Context.Users.Where(x => x.Id == userId) .Select(x => x.Student.AssignedCourseProjects.FirstOrDefault().CourseProject.LecturerId) .Single() ?? 0; //secretaryId = Context.Users.Where(x => x.Id == userId).Select(x => x.Student.Group.SecretaryId).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> GetPercentageGraphsForLecturer(int lecturerId, GetPagedListParams parms, int secretaryId) { AuthorizationHelper.ValidateLecturerAccess(Context, lecturerId); parms.SortExpression = "Date"; return(GetPercentageGraphDataForLecturerQuery(lecturerId, secretaryId, 2).ApplyPaging(parms)); }
public PagedList <StudentData> GetGraduateStudentsForGroup(int userId, int groupId, int subjectId, GetPagedListParams parms, bool getBySecretaryForStudent = true) { var secretaryId = 0; if (parms.Filters.ContainsKey("secretaryId")) { int.TryParse(parms.Filters["secretaryId"], out secretaryId); } var searchString = ""; if (parms.Filters.ContainsKey("searchString")) { searchString = parms.Filters["searchString"]; } var isStudent = AuthorizationHelper.IsStudent(Context, userId); var isLecturer = AuthorizationHelper.IsLecturer(Context, userId); if (isStudent) { 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 => x.GroupId == groupId) .Where(x => x.AssignedCourseProjects.Any(a => a.CourseProject.SubjectId == subjectId)) .Where(x => x.AssignedCourseProjects.Any(a => a.CourseProject.LecturerId == userId)); if (searchString.Length > 0) { return((from s in query let lecturer = s.AssignedCourseProjects.FirstOrDefault().CourseProject.Lecturer let cp = s.AssignedCourseProjects.FirstOrDefault() where cp.CourseProject.Theme.Contains(searchString) || s.LastName.Contains(searchString) 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.AssignedCourseProjects.FirstOrDefault().CourseProject.Theme, 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)); } 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.AssignedCourseProjects.FirstOrDefault().CourseProject.Theme, 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)); }
public IActionResult Get([ModelBinder] GetPagedListParams parms) { var result = PercentageService.GetPercentageGraphs(/*todo #auth WebSecurity.CurrentUserId*/ 2, parms); return(Ok(result)); }
public PagedList <CourseProjectData> Get([ModelBinder] GetPagedListParams parms) { return(CpManagementService.GetProjects(WebSecurity.CurrentUserId, parms)); }
public PagedList <StudentData> GetGraduateStudentsForUser(int userId, 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.AssignedDiplomProjects.FirstOrDefault().DiplomProject.LecturerId) .Single() ?? 0; } } if (string.IsNullOrWhiteSpace(parms.SortExpression) || parms.SortExpression == "Id") { parms.SortExpression = "Name"; } var query = Context.GetGraduateStudents() .Where(x => isLecturerSecretary || isStudent && getBySecretaryForStudent || x.AssignedDiplomProjects.Any(asd => asd.DiplomProject.LecturerId == userId)) .Where(x => secretaryId == 0 || x.Group.SecretaryId == secretaryId); return((from s in query let lecturer = s.AssignedDiplomProjects.FirstOrDefault().DiplomProject.Lecturer select new StudentData { Id = s.Id, Name = s.LastName + " " + s.FirstName + " " + s.MiddleName, //todo Mark = s.AssignedDiplomProjects.FirstOrDefault().Mark, AssignedDiplomProjectId = s.AssignedDiplomProjects.FirstOrDefault().Id, Lecturer = lecturer.LastName + " " + lecturer.FirstName + " " + lecturer.MiddleName, //todo Group = s.Group.Name, PercentageResults = s.PercentagesResults.Select(pr => new PercentageResultData { Id = pr.Id, PercentageGraphId = pr.DiplomPercentagesGraphId, StudentId = pr.StudentId, Mark = pr.Mark, Comment = pr.Comments }), DipomProjectConsultationMarks = s.DiplomProjectConsultationMarks.Select(cm => new DipomProjectConsultationMarkData { Id = cm.Id, ConsultationDateId = cm.ConsultationDateId, StudentId = cm.StudentId, Mark = cm.Mark, Comments = cm.Comments }) }).ApplyPaging(parms)); }
public PagedList <StudentData> Get([ModelBinder] GetPagedListParams parms) { return(DpManagementService.GetStudentsByDiplomProjectId(parms)); }
public IActionResult Get([ModelBinder] GetPagedListParams parms) { var result = CpManagementService.GetStudentsByCourseProjectId(parms); return(Ok(result)); }
public IActionResult Get([ModelBinder] GetPagedListParams parms) { var result = CpManagementService.GetProjects(/*todo #auth WebSecurity.CurrentUserId*/ 2, parms); return(Ok(result)); }