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);
        }
        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);
        }
Example #3
0
        public bool Edit(NomeBaseViewModel usuario, Guid id)
        {
            if (string.IsNullOrEmpty(usuario.Nome))
            {
                throw new ApiException(ApiErrorCodes.INVNOME, nameof(usuario.Nome));
            }

            Usuario _usuario = _repository.GetById(id);

            if (_usuario == null)
            {
                throw new ApiException(ApiErrorCodes.INVUSU);
            }

            _usuario = _mapper.Map(usuario, _usuario);

            _repository.Update(_usuario);

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

            return(true);
        }
Example #4
0
        public IActionResult Create(NomeBaseViewModel jogo)
        {
            if (!Request.Headers.TryGetValue(ControllersConstants.UsuarioId, out StringValues uId) ||
                !Guid.TryParse(uId, out Guid usuarioId))
            {
                throw new ApiException(ApiErrorCodes.INVUSU);
            }

            bool _result = _service.Create(jogo, usuarioId);

            return(Ok(_result));
        }
Example #5
0
        public IActionResult Edit(NomeBaseViewModel jogo, Guid id)
        {
            bool _result = _service.Edit(jogo, id);

            return(Ok(_result));
        }