public static IEnumerable <string> ValidarParaExcluir(FormaRecebimento entidade)
 {
     if (entidade == null)
     {
         yield return(Mensagem.EntidadeNaoEncontrada.Formatar(Termo.FormaRecebimento));
     }
 }
예제 #2
0
 public static FormaRecebimentoViewModel TransformarModelEmView(this FormaRecebimento entidade)
 {
     return(new FormaRecebimentoViewModel
     {
         Id = entidade.Id,
         Descricao = entidade.Descricao,
         Taxa = entidade.Taxa,
         QtdDiasParaReceber = entidade.QtdDiasParaReceber
     });
 }
        public IActionResult ObterPorId(int id)
        {
            FormaRecebimento formaRecebimento = _formaRecebimentoServico.ObterPorId(id);

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

            return(Ok(formaRecebimento.TransformarModelEmView()));
        }
예제 #4
0
        public bool Salvar(FormaRecebimentoDTO dto)
        {
            if (!UsuarioLogado.IsInRole(Funcionalidade.FormaRecebimentoGravar))
            {
                messageQueue.Add(Resource.Sigim.ErrorMessages.PrivilegiosInsuficientes, TypeMessage.Error);
                return(false);
            }

            if (dto == null)
            {
                throw new ArgumentNullException("dto");
            }

            if (dto.NumeroDias.HasValue)
            {
                if (dto.NumeroDias.Value < 0)
                {
                    messageQueue.Add("O número de dias não pode ser menor que zero !", TypeMessage.Error);
                    return(false);
                }
            }

            bool novoItem = false;

            var formaRecebimento = formaRecebimentoRepository.ObterPeloId(dto.Id);

            if (formaRecebimento == null)
            {
                formaRecebimento = new FormaRecebimento();
                novoItem         = true;
            }
            if (formaRecebimento.Automatico == true)
            {
                return(false);
            }

            formaRecebimento.Descricao       = dto.Descricao;
            formaRecebimento.Automatico      = dto.Automatico;
            formaRecebimento.TipoRecebimento = dto.TipoRecebimento;
            formaRecebimento.NumeroDias      = dto.NumeroDias;
            if (!dto.NumeroDias.HasValue)
            {
                formaRecebimento.NumeroDias = 0;
            }

            if (Validator.IsValid(formaRecebimento, out validationErrors))
            {
                if (novoItem)
                {
                    formaRecebimentoRepository.Inserir(formaRecebimento);
                }
                else
                {
                    formaRecebimentoRepository.Alterar(formaRecebimento);
                }

                formaRecebimentoRepository.UnitOfWork.Commit();
                messageQueue.Add(Resource.Sigim.SuccessMessages.SalvoComSucesso, TypeMessage.Success);
                return(true);
            }
            else
            {
                messageQueue.AddRange(validationErrors, TypeMessage.Error);
                return(false);
            }
        }
예제 #5
0
        public static FormaRecebimento TransformarViewEmModel(this FormaRecebimentoViewModel viewModel, FormaRecebimento entidade)
        {
            entidade.Id                 = viewModel.Id;
            entidade.Descricao          = viewModel.Descricao;
            entidade.Taxa               = viewModel.Taxa;
            entidade.QtdDiasParaReceber = viewModel.QtdDiasParaReceber;

            return(entidade);
        }