Ejemplo n.º 1
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "Bad request!");
            }

            var projectTask = projectTasksRepository.GetProjectTaskById(id);

            if (projectTask == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, "Not found!");
            }

            if (!coursesRepository.IsInCourse(projectTask.Project.CourseId, User.Identity.GetUserId(), User.IsInRole("Administrator")))
            {
                throw new HttpException((int)HttpStatusCode.Forbidden, "Forbidden!");
            }


            var isTeacher = (coursesRepository.IsTeacherInCourse(projectTask.Project.CourseId, User.Identity.GetUserId(), User.IsInRole("Administrator")));

            ViewBag.IsTeacher = isTeacher;
            ViewBag.AllUsers  = (from u in userCoursesRepostiory.GetUserCoursesByCourseId(projectTask.Project.CourseId)
                                 where u.CoderRole == CoderRole.Student
                                 select u.ApplicationUser).ToList();
            ViewBag.BestSubmission = submissionsRepository.GetBestUserSubmissionForTask(id.Value, User.Identity.GetUserId());

            if (isTeacher || User.IsInRole("Administrator"))
            {
                ViewBag.Submissions = submissionsRepository.GetSubmissionsForProjectTaskId(id.Value);
            }
            else
            {
                if (DateTime.Now < projectTask.Project.Start && !coursesRepository.IsAssistantTeacherInCourse(projectTask.Project.CourseId, User.Identity.GetUserId(), User.IsInRole("Administrator")))
                {
                    throw new HttpException((int)HttpStatusCode.Forbidden, "Forbidden!");
                }
                ViewBag.Submissions = submissionsRepository.GetSubmissionsForUserId(User.Identity.GetUserId());
            }
            if (ViewBag.Submissions != null)
            {
                ViewBag.Submissions = ((IEnumerable <Submission>)ViewBag.Submissions).OrderByDescending(i => i.Id);
            }
            return(View(projectTask));
        }
Ejemplo n.º 2
0
        public double GetValue(Project projects)
        {
            double currentValue = 0;
            double totalValue   = 0;

            foreach (var task in projects.ProjectTasks)
            {
                var bestSubmisson = submissionsRepository.GetBestUserSubmissionForTask(task.Id, User.Identity.GetUserId());
                if (bestSubmisson != null && bestSubmisson.Status == TestResultStatus.Accepted)
                {
                    currentValue += task.Value;
                }
                totalValue += task.Value;
            }

            if (totalValue == 0)
            {
                return(0);
            }

            return(Math.Round((currentValue / totalValue) * 100));
        }
Ejemplo n.º 3
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "Bad request!");
            }

            var project = projectsRepository.GetProjectById(id);

            if (project == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, "Not found!");
            }

            if (!coursesRepository.IsInCourse(project.CourseId, User.Identity.GetUserId(), User.IsInRole("Administrator")))
            {
                throw new HttpException((int)HttpStatusCode.Forbidden, "Forbidden!");
            }

            if (coursesRepository.IsTeacherInCourse(project.CourseId, User.Identity.GetUserId(), User.IsInRole("Administrator")))
            {
                ViewBag.IsTeacher = true;
            }
            else
            {
                // Checking if the project hasn't started yet
                if (DateTime.Now < project.Start && !User.IsInRole("Administrator") && !coursesRepository.IsAssistantTeacherInCourse(project.CourseId, User.Identity.GetUserId(), User.IsInRole("Administrator")))
                {
                    throw new HttpException((int)HttpStatusCode.Forbidden, "Forbidden!");
                }
            }

            double totalGrade  = 0;
            double totalGrades = 0;
            double totalValue  = 0;

            foreach (var task in project.ProjectTasks)
            {
                var gradeProjectTask = task.GradeProjectTasks.Where(g => g.UserId == User.Identity.GetUserId()).FirstOrDefault();
                if (gradeProjectTask != null)
                {
                    totalGrade += task.GradeProjectTasks.Where(g => g.UserId == User.Identity.GetUserId()).FirstOrDefault().Grade *task.Value;
                    totalValue += task.Value;
                    totalGrades++;
                }
            }
            if (totalGrades == project.ProjectTasks.Count && (project.ProjectTasks.Count > 0))
            {
                ViewBag.Grade = Math.Round(totalGrade / totalValue, 2);
            }
            else
            {
                ViewBag.Grade = "All tasks haven't been graded yet.";
            }

            var taskViewModels = new List <TaskViewModel>();

            foreach (var task in project.ProjectTasks)
            {
                taskViewModels.Add(new TaskViewModel
                {
                    BestSubmission = submissionsRepository.GetBestUserSubmissionForTask(task.Id, User.Identity.GetUserId()),
                    Task           = task
                });
            }

            var view = new ProjectDetailsViewModel
            {
                Project = project,
                Tasks   = taskViewModels
            };

            return(View(view));
        }