Beispiel #1
0
        public bool Salvar(ProfissaoDTO dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException("dto");
            }

            bool novoItem = false;

            var profissao = profissaoRepository.ObterPeloId(dto.Id);

            if (profissao == null)
            {
                profissao = new Profissao();
                novoItem  = true;
            }

            profissao.Descricao  = dto.Descricao;
            profissao.Automatico = dto.Automatico;

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

                profissaoRepository.UnitOfWork.Commit();
                messageQueue.Add(Resource.Sigim.SuccessMessages.SalvoComSucesso, TypeMessage.Success);
                return(true);
            }
            else
            {
                messageQueue.AddRange(validationErrors, TypeMessage.Error);
            }

            return(false);
        }