示例#1
0
        public async Task <IActionResult> OnGetAsync()
        {
            var username = HttpContext.Session.GetString("_username");
            var usertype = HttpContext.Session.GetString("_usertype");
            var access   = new Access(username, "Student");

            if (access.IsLogin())
            {
                if (access.IsAuthorize(usertype))
                {
                    Student = await _context.Student
                              .Where(s => s.DateDeleted == null)
                              .FirstOrDefaultAsync(s => s.AssignedId == username);

                    SubmissionType = await _context.SubmissionType
                                     .Where(s => s.DateDeleted == null)
                                     .Where(s => s.BatchId == Student.BatchId)
                                     .Where(s => s.StartDate <= DateTime.Now)
                                     .Where(s => s.GraceDate >= DateTime.Now)
                                     .FirstOrDefaultAsync();

                    // check if submitted
                    HasSubmit = false;

                    if (Student.ProjectId != null)
                    {
                        Project = await _context.Project
                                  .Where(p => p.DateDeleted == null)
                                  .FirstOrDefaultAsync(p => p.ProjectId == Student.ProjectId);

                        Submissions = await _context.Submission
                                      .Where(s => s.DateDeleted == null)
                                      .Where(w => w.ProjectId == Project.ProjectId)
                                      .Include(w => w.Project)
                                      .ToListAsync();

                        if (Submissions.Count() > 0 && SubmissionType != null)
                        {
                            foreach (var submission in Submissions)
                            {
                                if (submission.SubmissionTypeId == SubmissionType.SubmissionTypeId)
                                {
                                    HasSubmit = true;
                                    break;
                                }
                            }
                        }
                    }

                    return(Page());
                }
                else
                {
                    ErrorMessage = "Access Denied";
                    return(RedirectToPage($"/{usertype}/Index"));
                }
            }
            else
            {
                ErrorMessage = "Login Required";
                return(RedirectToPage("/Account/Login"));
            }
        }