Пример #1
0
        public IHttpActionResult PutUpdateGrade(int gradeId, GradeDto gradeDto)
        {
            var userData = IdentityHelper.GetLoggedInUser(RequestContext);

            logger.Info("Update Grade {@gradeData} for Grade {@gradeId} by {@userData}", gradeDto, gradeId, userData);

            if (gradeId != gradeDto.GradeId)
            {
                return(BadRequest("Ids do not match"));
            }

            if (userData.UserRole == "teachers")
            {
                if (gradeDto.TeacherId != userData.UserId)
                {
                    throw new UnauthorizedAccessException();
                }
            }

            GradeDto result = gradesService.UpdateGrade(gradeDto);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
Пример #2
0
        public IHttpActionResult UpdateGrade(int id, Grade grade)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Grade updatedGrade = gradesService.UpdateGrade(id, grade);

            if (updatedGrade == null)
            {
                return(NotFound());
            }

            return(Ok(updatedGrade));
        }