Example #1
0
        public async Task <IActionResult> Update(int id, StudentAssignmentDto assignmentDto)
        {
            StudentAssignment assignment = await _assignmentService.GetStudentAssignmentById(id);

            if (assignment == null)
            {
                return(NotFound());
            }
            if (assignment.StudentId != _userService.UserId)
            {
                return(Forbid());
            }
            if (!_assignmentService.IsAllowedToUpdate(assignment))
            {
                return(BadRequest("Вы не можете редактировать работу"));
            }

            assignmentDto.AssignmentId = assignment.Id;
            _mapper.Map(assignmentDto, assignment);
            _db.Update(assignment);

            await _db.SaveChangesAsync();

            return(Ok());
        }
Example #2
0
        public StudentAssignment Add(StudentAssignmentDto assignmentDto, User student, int assignmentId)
        {
            StudentAssignment studentAssignment = _mapper.Map <StudentAssignment>(assignmentDto);

            studentAssignment.StudentId        = student.UserId;
            studentAssignment.Status           = AssignmentStatus.Submitted;
            studentAssignment.LastStatusChange = DateTime.UtcNow;
            studentAssignment.Submitted        = DateTime.UtcNow;
            studentAssignment.AssignmentId     = assignmentId;

            var attachments = _db.StudentAssignmentAttachment
                              .Where(x => assignmentDto.Attachments.Select(y => y.Id).Contains(x.Id) && x.UserId == student.UserId)
                              .ToList();

            attachments.ForEach(x => x.Assignment = studentAssignment);
            _db.UpdateRange(attachments);
            return(_db.Add(studentAssignment).Entity);
        }
Example #3
0
        public async Task <IActionResult> Submit(int assignmentId, StudentAssignmentDto assignmentDto)
        {
            #region Checks

            AssignmentWithConcrete assignment =
                await _assignmentService.GetAssignmentById(assignmentId, _userService.UserId);

            if (assignment == null)
            {
                return(NotFound());
            }
            if (assignment.StudentAssignment != null)
            {
                return(Conflict());
            }

            Group group = await _groupService.GetByIdAsync(assignmentDto.GroupId);

            if (group == null)
            {
                return(NotFound());
            }
            if (!_groupService.StudentExists(_userService.UserId, group.Id))
            {
                return(Forbid());
            }

            #endregion

            StudentAssignment studentAssignment =
                _assignmentService.Add(assignmentDto, _userService.CurrentUser, assignmentId);
            studentAssignment.GroupId = group.Id;
            await _db.SaveChangesAsync();

            //await _teacherHub.NewAssignment(assignmentId, studentAssignment.Id, assignment.Assignment.TeacherId);

            return(CreatedAtAction(nameof(GetById), new { studentAssignment.Id },
                                   _mapper.Map <StudentAssignmentDto>(assignment.StudentAssignment)));
        }