Пример #1
0
        public async Task <IActionResult> Add(AssignmentDetailsDto assignmentDto)
        {
            Subject subject = await _db.Subjects.FindAsync(assignmentDto.SubjectId);

            if (subject.TeacherId != _userService.UserId)
            {
                return(Forbid());
            }
            Assignment assignment = await _assignmentService.AddAsync(assignmentDto, subject);

            await _db.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetById), new { assignment.Id }, _mapper.Map <AssignmentDetailsDto>(assignment)));
        }
Пример #2
0
        public async Task <Assignment> AddAsync(AssignmentDetailsDto assignmentDto, Subject subject)
        {
            Assignment assignment = (await _db.Assignments.AddAsync(_mapper.Map <Assignment>(assignmentDto))).Entity;

            assignment.TeacherId = _userService.UserId;
            assignment.Subject   = subject;
            await _db.SaveChangesAsync();

            await _db.AssignmentAttachments
            .Where(x => assignmentDto.Attachments.Select(y => y.Id).Contains(x.Id) &&
                   x.UserId == _userService.UserId)
            .UpdateAsync(x => new AssignmentAttachment {
                AssignmentId = assignment.Id
            });

            await _db.Entry(assignment).Collection(x => x.Attachments).LoadAsync();

            return(assignment);
        }