Esempio n. 1
0
        public IActionResult Assignment(string Id)
        {
            var user = userManager.GetUserAsync(User).GetAwaiter().GetResult();
            var role = userManager.GetRolesAsync(user).GetAwaiter().GetResult();

            if (role[0] == "Teacher")
            {
                var homework   = homeworkServices.getByAssignmentId(Id);
                var grade      = gradeServices.getByAssignmentId(Id);
                var assignment = assignmentsServices.GetByID(Id);
                var viewModel  = new AssignmentViewModel()
                {
                    Grades    = grade,
                    Homeworks = homework,
                    Link      = assignment.Link,
                    Type      = assignment.Type
                };
                return(View(viewModel));
            }
            else
            if (role[0] == "Student")
            {
                float grade      = 0;
                var   assignment = assignmentsServices.GetByID(Id);
                var   homework   = homeworkServices.getbyUserAndAssignment(userManager.GetUserId(User), assignment.AssignmentID.ToString());
                if (homework == true)
                {
                    var mark = gradeServices.getByUserAndAssignment(userManager.GetUserId(User), Id);
                    if (mark != null)
                    {
                        grade = mark.Mark;
                    }
                }
                var viewModel = new AssignmentViewModel()
                {
                    Id          = Guid.Parse(Id),
                    DueTo       = assignment.DueTo,
                    Link        = assignment.Link,
                    Description = assignment.Description,
                    Type        = assignment.Type,
                    Status      = homework,
                    Mark        = grade
                };

                return(View(viewModel));
            }
            return(View());
        }
        public IActionResult Index(AssignmentViewModel model)
        {
            var assignment = assignmentServices.GetByID(model.Id.ToString());
            var user       = userServices.GetById(userManager.GetUserId(User));

            homeworkServices.Add(assignment, user, model.HomeworkLink);
            return(RedirectToAction("Assignment", "Assignment", new { id = model.Id }));
        }