예제 #1
0
        public void UpdateCommand_Invalido()
        {
            var command = new TaxaSelicUpdateCommand(0, 2000, 1, 3);

            command.Validate();
            var validacaoId = command.Invalid;

            command = new TaxaSelicUpdateCommand(1, 2000, 1, 3);
            command.Validate();
            var validacaoAno = command.Invalid;

            command = new TaxaSelicUpdateCommand(1, 2017, 13, 3);
            command.Validate();
            var validacaoMes = command.Invalid;

            command = new TaxaSelicUpdateCommand(1, 2017, 13, 0);
            command.Validate();
            var validacaoValor = command.Invalid;


            Assert.True(validacaoId);
            Assert.True(validacaoAno);
            Assert.True(validacaoMes);
            Assert.True(validacaoValor);
        }
예제 #2
0
        public void UpdateCommand_valido()
        {
            var taxaSelicUpdateCommand = new TaxaSelicUpdateCommand(1, 2017, 1, 3);

            taxaSelicUpdateCommand.Validate();
            var validacao = taxaSelicUpdateCommand.Invalid;

            Assert.False(validacao);
        }
        public IActionResult Update(
            [FromBody] TaxaSelicUpdateCommand command,
            [FromServices] TaxaSelicService service,
            [FromServices] IMemoryCache cache
            )
        {
            GenericResult result = service.Exec(command);

            if (result.Status == 200)
            {
                cache.Remove(command.Id);
            }

            return(StatusCode(result.Status, result));
        }
        public GenericResult Exec(TaxaSelicUpdateCommand command)
        {
            TaxaSelicModel model = _repository.GetByAnoeMes(command.Ano, command.Mes);

            if ((model != null) && (model.Id != command.Id))
            {
                command.AddNotification("TaxaSelicModel", "Recurso já existente Id: " + model.Id);
            }


            model = _repository.GetById(command.Id);
            if (model == null)
            {
                command.AddNotification("Id", "Recurso Inexistente");
            }


            command.Validate();
            if (command.Invalid)
            {
                return(new GenericResult(400, "Recurso Inválido", command.Notifications));
            }


            model.Atualizar(command.Ano, command.Mes, command.Valor);

            try
            {
                _repository.Update(model);

                return(new GenericResult(200, "Recurso Atualizado", model));
            }
            catch (System.Exception ex)
            {
                return(new GenericResult(503, ex.GetBaseException().Message, null));
            }
        }