Beispiel #1
0
        public IActionResult Put(int id, [FromBody] RoleDto dto, [FromServices] UpdateRoleValidator validator)
        {
            dto.Id = id;

            var role = _context.Roles.Find(id);

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

            var result = validator.Validate(dto);

            if (!result.IsValid)
            {
                throw new Exception();// prepraviti sa klasom error/ medelja 5-subota termin
            }

            _mapper.Map(dto, role);

            try
            {
                _context.SaveChanges();
                return(NoContent());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Beispiel #2
0
        public ValidationResult GetValidationResult(UpdateRole model)
        {
            var validator = new UpdateRoleValidator(_repository);

            return(validator.Validate(model));
        }