Esempio n. 1
0
 public CheckRoleResult CheckCourseRole(long? id)
 {
     var result = new CheckRoleResult();
     if (id == null)
     {
         result.ActionResult = RedirectErrorPage(Url.Action("Index", "Home"));
         result.IsValid = false;
     }
     else
     {
         var userid = User.Identity.GetUserId();
         var account = DbContext.Accounts.FirstOrDefault(s => s.Id == userid);
         // ReSharper disable once PossibleNullReferenceException
         var course = account.Courses.FirstOrDefault(s => s.CourseId == id && s.Actived);
         if (course == null)
         {
             result.ActionResult = RedirectErrorPage(Url.Action("Index", "Home"));
             result.IsValid = false;
         }
         else
         {
             result.Course = course;
             result.Account = account;
             result.IsValid = true;
         }
     }
     return result;
 }
Esempio n. 2
0
 public CheckRoleResult CheckGroupRole(long? id)
 {
     var result = new CheckRoleResult();
     if (id == null)
     {
         result.ActionResult = RedirectErrorPage();
         result.IsValid = false;
     }
     else
     {
         var group = DbContext.Groups.Find(id);
         if (group == null)
         {
             result.ActionResult = RedirectErrorPage();
             result.IsValid = false;
         }
         else
         {
             if (group.Course.TeacherId != User.Identity.GetUserId())
             {
                 result.ActionResult = RedirectAccessDeniedPage();
                 result.IsValid = false;
             }
             else
             {
                 result.Group = group;
                 result.IsValid = true;
             }
         }
     }
     return result;
 }
Esempio n. 3
0
        private List<Test> GetSubmitNo(List<Test> tests, CheckRoleResult result)
        {
            var answerSheets = result.Account.AnswerSheets.ToList();
            foreach (var answersheet in answerSheets)
            {
                var test = tests.Find(s => s.TestId == answersheet.TestId);

                if (test != null)
                {
                    test.SubmitNoUser++;
                    test.Scores.Add(answersheet.Score);
                }
            }
            return tests;
        }