Ejemplo n.º 1
0
        public GenericResponse ModificarDatosUsuario(UpdateUsuarioRequest request, string _operation)
        {
            GenericResponse _response = new GenericResponse();

            try
            {
                if (_conectorBD.UpdateDatosUsuario(request, _operation))
                {
                    Informacion.LogInformacion(LogManager.GetCurrentClassLogger(), " [ " + GerenteLog.GetObtenerMetodo() + " ] -- [ " + _operation + " ]. Se Modifico al cliente con email: " + request.correoElectronico + " , de manera correcta.");
                    _response.codigo  = GerenteCodigo.GetCodigo("OK");
                    _response.mensaje = GerenteMensaje.GetMensaje("OK");
                    _response.exito   = true;
                }
                else
                {
                    Informacion.LogInformacion(LogManager.GetCurrentClassLogger(), " [ " + GerenteLog.GetObtenerMetodo() + " ] -- [ " + _operation + " ]. Ocurrio un error al modificar al cliente con email: " + request.correoElectronico);
                    _response.codigo  = GerenteCodigo.GetCodigo("ERROR_FATAL");
                    _response.mensaje = GerenteMensaje.GetMensaje("ERROR_FATAL");
                    _response.exito   = false;
                }
            }
            catch (Exception ex)
            {
                _response.codigo  = GerenteCodigo.GetCodigo("ERROR_FATAL");
                _response.mensaje = GerenteMensaje.GetMensaje("ERROR_FATAL");
                _response.exito   = false;
                Informacion.LogError(LogManager.GetCurrentClassLogger(), " [ " + GerenteLog.GetObtenerMetodo() + " ] -- [ " + _operation + " ].Se genero un error inesperado. ", ex);
            }
            return(_response);
        }
Ejemplo n.º 2
0
        public string ModificarData(UpdateUsuarioRequest request)
        {
            _operation       = GerenteOperacion.GenerarOperacion();
            _conectorNegocio = new NegocioObtenerDatos();
            GenericResponse _response = new GenericResponse();
            bool            estado    = false;

            try
            {
                Informacion.LogInformacion(LogManager.GetCurrentClassLogger(), " [ " + GerenteLog.GetObtenerMetodo() + " ] -- [ " + _operation + " ] REQUEST: " + GerenteJson.SerializeObject(request));
                if (ModelState.IsValid)
                {
                    _response = _conectorNegocio.VerificarCanal(request.Canal, request.PassCanal, _operation, ref estado);
                    if (!estado)
                    {
                        return(GerenteJson.SerializeObject(_response));
                    }
                    _response = _conectorNegocio.ModificarDatosUsuario(request, _operation);
                    Informacion.LogInformacion(LogManager.GetCurrentClassLogger(), " [ " + GerenteLog.GetObtenerMetodo() + " ] -- [ " + _operation + " ] RESPONSE: " + GerenteJson.SerializeObject(_response));
                }
                else
                {
                    var errors = string.Join(" | ", ModelState.Values
                                             .SelectMany(v => v.Errors)
                                             .Select(e => e.ErrorMessage));
                    _response.mensaje = Convert.ToString(errors);
                    return(GerenteJson.SerializeObject(_response));
                }
            }
            catch (Exception ex)
            {
                Informacion.LogError(LogManager.GetCurrentClassLogger(), " [ " + GerenteLog.GetObtenerMetodo() + " ] -- [ " + _operation + " ]. Se genero un error en Modificar los datos.", ex);
            }
            return(JsonConvert.SerializeObject(_response));
        }
        public bool UpdateDatosUsuario(UpdateUsuarioRequest request, string _operation)
        {
            bool _response = false;

            try
            {
                string         nombreSp = "[api].[UPDATE_DATOS_USUARIO]";
                StoreProcedure sp       = new StoreProcedure(nombreSp);
                sp.AgregarParametro("@USSER", request.nameUser, Direccion.Input);
                sp.AgregarParametro("@PASS", request.passUser, Direccion.Input);
                sp.AgregarParametro("@CORREO", request.correoElectronico, Direccion.Input);
                sp.AgregarParametro("@CELULAR", request.celular, Direccion.Input);
                sp.EjecutarStoreProcedure(strConexion_wpp);
                if (sp.Error.Trim() != String.Empty)
                {
                    _response = false;
                    throw new Exception("Procedimiento Almacenado: " + nombreSp + " Descripcion: " + sp.Error.Trim());
                }
                _response = true;
            }
            catch (Exception ex)
            {
                Informacion.LogError(LogManager.GetCurrentClassLogger(), " [ " + GerenteLog.GetObtenerMetodo() + " ] -- [ " + _operation + " ]. Se genero un error inesperado en Base de Datos BD_DATOS", ex);
            }
            return(_response);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Validaçao de usuário
        /// </summary>
        /// <param name="request">Objeto enviado</param>
        /// <param name="existing">Registro que contém no banco</param>
        /// <returns></returns>
        private ErrorResponse Validate(UpdateUsuarioRequest request, Usuario existing)
        {
            var listError = new List <string>();

            if (existing == null)
            {
                listError.Add("Usuário não encontrado.");
            }

            if (request.StatusId <= 0)
            {
                listError.Add("Informar o status");
            }

            if (string.IsNullOrEmpty(request.PerfilId))
            {
                listError.Add("Informar o perfil");
            }

            if (string.IsNullOrEmpty(request.Email))
            {
                listError.Add("Informar o e-mail");
            }

            if (listError.Any())
            {
                return(new ErrorResponse(Guid.NewGuid(), "Alguns itens na validação precisam da sua atenção", EnumResponseCode.Generico, listError));
            }

            return(null);
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Update(UpdateUsuarioRequest request)
        {
            var existing = await Find(request.Id);

            var validError = Validate(request, existing);

            if (validError != null)
            {
                return(BadRequest(validError));
            }

            // atualiza os dados do usuário
            existing.Email    = request.Email;
            existing.StatusId = request.StatusId;

            // remove as roles pré-existentes e cadastra as novas
            existing.Roles.RemoveAll(x => x.UserId.Equals(request.Id));
            existing.Roles.Add(new IdentityUserRole <string>()
            {
                RoleId = request.PerfilId,
                UserId = request.Id
            });

            // remove as BUs pré-existentes e cadastra as novas
            var claims = await _userManager.GetClaimsAsync(existing);

            if (claims != null && claims.Any(x => x.Type.Equals(IdentityServerApiConstants.StandardClaims.BusinessUnit)))
            {
                await _userManager.RemoveClaimsAsync(existing, claims.Where(x => x.Type.Equals(IdentityServerApiConstants.StandardClaims.BusinessUnit)));
            }

            foreach (var item in request.BUs)
            {
                existing.Claims.Add(new IdentityUserClaim <string>()
                {
                    UserId     = request.Id,
                    ClaimType  = IdentityServerApiConstants.StandardClaims.BusinessUnit,
                    ClaimValue = item.ToString()
                });
            }

            await _userManager.UpdateAsync(existing);

            return(NoContent());
        }
        public string UpdateDatos(UpdateUsuarioRequest request)
        {
            string _operation = String.Empty;
            string _response  = String.Empty;

            _conectorNegocio = new NegocioObtenerDatos();
            try
            {
                if (ModelState.IsValid)
                {
                    _conectorNegocio.ModificarDatosUsuario(request, _operation);
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
            }
            return(_response);
        }