Пример #1
0
        public IHttpActionResult Put([FromBody] Jogo jogo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                //TODO: Teste >> jogo.GolsMandante = -1; Ok

                JogoValidation   validator = new JogoValidation();
                ValidationResult result    = validator.Validate(jogo);
                if (!result.IsValid)
                {
                    var erros = "";
                    result.Errors.ToList()
                    .ForEach(e => erros +=
                                 string.Format($"{e.PropertyName} : {e.ErrorMessage}\n"));

                    return(BadRequest(erros));
                }

                RepositoryJogos.Atualizar(jogo);
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public bool Edit(NomeBaseViewModel jogo, Guid id)
        {
            ValidationResult _result = new JogoValidation().Validate(jogo);

            if (!_result.IsValid)
            {
                throw new ApiException(_result.GetErrors(), ApiErrorCodes.MODNOTVALD);
            }

            Jogo _jogo = _repository.GetById(id);

            if (_jogo == null)
            {
                throw new ApiException(ApiErrorCodes.INVJOGO);
            }

            _jogo = _mapper.Map(jogo, _jogo);

            _repository.Update(_jogo);

            if (!_uow.Commit())
            {
                throw new ApiException(ApiErrorCodes.ERROPBD);
            }

            return(true);
        }
Пример #3
0
        public bool Create(NomeBaseViewModel jogo, Guid usuarioId)
        {
            if (!_repositoryUsuario.ExistsWithId(usuarioId))
            {
                throw new ApiException(ApiErrorCodes.INVUSU);
            }

            ValidationResult _result = new JogoValidation().Validate(jogo);

            if (!_result.IsValid)
            {
                throw new ApiException(_result.GetErrors(), ApiErrorCodes.MODNOTVALD);
            }

            Jogo _jogo = _mapper.Map <Jogo>(jogo);

            _jogo.SetCreatorId(usuarioId);

            _repository.Create(_jogo);

            if (!_uow.Commit())
            {
                throw new ApiException(ApiErrorCodes.ERROPBD);
            }

            return(true);
        }
Пример #4
0
 public bool IsValid()
 {
     ValidationResult = new JogoValidation().Validate(this);
     return(ValidationResult.IsValid);
 }