public IActionResult UpdateAssignment(Guid courseId, Guid id, [FromBody] AssignmentForUpdateDto assignment)
        {
            if (assignment == null)
            {
                _logger.LogError("AssignmentForUpdateDto object sent from client is null.");
                return(BadRequest("ssignmentForUpdateDto object is null"));
            }

            var course = _repository.Course.GetCourse(courseId, trackChanges: false);

            if (course == null)
            {
                _logger.LogInfo($"Course with id: {courseId} doesn't exist in the database.");
                return(NotFound());
            }

            var assignmentEntity = _repository.Assignment.GetAssignment(courseId, id, trackChanges: true);

            if (assignmentEntity == null)
            {
                _logger.LogInfo($"Aassignment with id: {id} doesn't exist in the database.");
                return(NotFound());
            }

            _mapper.Map(assignment, assignmentEntity);
            _repository.Save();

            return(NoContent());
        }
        public IActionResult setGradeOfAssignment(AssignmentForUpdateDto assignmentForUpdateDto)
        {
            var assignment = _context.Assignments.FirstOrDefault(a => a.Id == assignmentForUpdateDto.Id);

            _mapper.Map(assignmentForUpdateDto, assignment);

            _context.SaveChanges();

            return(Ok(assignment));
        }
Beispiel #3
0
        public async Task <IActionResult> UpdateAssignment(int id, AssignmentForUpdateDto assignmentForUpdateDto)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var assignmentFromRepo = await _repo.GetAssignment(assignmentForUpdateDto.Id);

            _mapper.Map(assignmentForUpdateDto, assignmentFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating assignment {id} failed on save");
        }
Beispiel #4
0
        public async Task <IActionResult> UpdateAssignmentForEnrollment(Guid enrollmentId, Guid id, [FromBody] AssignmentForUpdateDto assignment)
        {
            var assignmentEntity = HttpContext.Items["assignment"] as Assignment;

            _mapper.Map(assignment, assignmentEntity);
            await _repository.SaveAsync();

            return(NoContent());
        }
Beispiel #5
0
        public async Task <IActionResult> UpdateAssignmentForCourse(Guid courseId, Guid id, [FromBody] AssignmentForUpdateDto assignment)
        {
            if (assignment == null)
            {
                _logger.LogError("AssignmentForUpdateDto object sent from client is null.");
                return(BadRequest("AssignmentForUpdateDto object is null"));
            }

            if (!ModelState.IsValid)
            {
                _logger.LogError("Invalid model state for the AssignmentForUpdateDto object");
                return(UnprocessableEntity(ModelState));
            }

            var course = await _repository.CourseMgt.GetCourseAsync(courseId, trackChanges : false);

            if (course == null)
            {
                _logger.LogInfo($"Course with id: {courseId} doesn't exist in the database.");
                return(NotFound());
            }

            var assignmentEntity = await _repository.Assignment.GetAssignmentAsync(courseId, id, trackChanges : true);

            if (assignmentEntity == null)
            {
                _logger.LogInfo($"Assignment with id: {id} doesn't exist in the database.");
                return(NotFound());
            }

            _mapper.Map(assignment, assignmentEntity);
            await _repository.SaveAsync();

            return(NoContent());
        }
        public IActionResult UpdateAssignmentForEnrollment(Guid enrollmentId, Guid id, [FromBody] AssignmentForUpdateDto assignment)
        {
            if (assignment == null)
            {
                _logger.LogError("AssignmentForUpdateDto object sent from client is null.");
                return(BadRequest("AssignmentForUpdateDto object is null"));
            }

            if (!ModelState.IsValid)
            {
                _logger.LogError("Invalid model state for the EmployeeForUpdateDto object");
                return(UnprocessableEntity(ModelState));
            }


            var enrollment = _repository.Enrollment.GetEnrollments(enrollmentId, trackChanges: false);

            if (enrollment == null)
            {
                _logger.LogInfo($"Enrollment with id: {enrollmentId} doesn't exist in the database.");
                return(NotFound());
            }

            var assignmentEntity = _repository.Assignment.GetAssignment(enrollmentId, id, trackChanges: true);

            if (assignmentEntity == null)
            {
                _logger.LogInfo($"Assignment with id: {id} doesn't exist in the database.");
                return(NotFound());
            }

            _mapper.Map(assignment, assignmentEntity);
            _repository.Save();

            return(NoContent());
        }