Esempio n. 1
0
        public ActionResult ValidaCentroCustoPorUsuario(string codigo, string modulo, bool somenteNivelFolha)
        {
            var centroCusto = centroCustoAppService.ObterPeloCodigo(codigo);

            if (!string.IsNullOrEmpty(codigo))
            {
                if ((somenteNivelFolha && !centroCustoAppService.EhCentroCustoUltimoNivelValido(centroCusto)) ||
                    !centroCustoAppService.EhCentroCustoValido(centroCusto) ||
                    !centroCustoAppService.UsuarioPossuiAcessoCentroCusto(centroCusto, Usuario.Id, modulo))
                {
                    var msg = messageQueue.GetAll()[0].Text;
                    messageQueue.Clear();
                    return(Json(new { ehValido = false, errorMessage = msg, descricao = string.Empty }));
                }
                return(Json(new { ehValido = true, errorMessage = string.Empty, descricao = centroCusto.Descricao }));
            }
            return(Json(new { ehValido = true, errorMessage = string.Empty, descricao = string.Empty }));
        }
Esempio n. 2
0
        public void Salvar(ParametrosUsuarioDTO dto)
        {
            if (!UsuarioLogado.IsInRole(Funcionalidade.ParametroUsuarioOrdemCompraGravar))
            {
                messageQueue.Add(Resource.Sigim.ErrorMessages.PrivilegiosInsuficientes, TypeMessage.Error);
                return;
            }

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

            bool novoItem = false;

            var parametrosUsuario = parametrosUsuarioRepository.ObterPeloId(dto.Id);

            if (parametrosUsuario == null)
            {
                parametrosUsuario = new ParametrosUsuario()
                {
                    Id = dto.Id
                };
                novoItem = true;
            }

            parametrosUsuario.Email = dto.Email;

            if (string.IsNullOrEmpty(dto.Email))
            {
                parametrosUsuario.Senha = string.Empty;
            }
            else if (!string.IsNullOrEmpty(dto.Senha))
            {
                parametrosUsuario.Senha = dto.Senha;
            }


            if (string.IsNullOrEmpty(dto.CentroCusto.Codigo))
            {
                parametrosUsuario.CodigoCentroCusto = null;
            }
            else
            {
                var centroCusto = centroCustoService.ObterPeloCodigo(dto.CentroCusto.Codigo);

                if (!centroCustoService.EhCentroCustoUltimoNivelValido(centroCusto))
                {
                    return;
                }

                if (!centroCustoService.UsuarioPossuiAcessoCentroCusto(dto.CentroCusto, dto.Id, NomeModulo.OrdemCompra))
                {
                    return;
                }

                parametrosUsuario.CodigoCentroCusto = centroCusto.Codigo;
            }

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

                parametrosUsuarioRepository.UnitOfWork.Commit();

                messageQueue.Add(Resource.Sigim.SuccessMessages.SalvoComSucesso, TypeMessage.Success);
            }
            else
            {
                messageQueue.AddRange(validationErrors, TypeMessage.Error);
            }
        }