Example #1
0
        public async Task <ActionResult> pvwAddPolicyRoles([FromBody] PolicyRolesDTO _sarpara)
        {
            PolicyRolesDTO _Policy = new PolicyRolesDTO();

            try
            {
                string     baseadress = config.Value.urlbase;
                HttpClient _client    = new HttpClient();
                _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
                var result = await _client.GetAsync(baseadress + "api/PolicyRoles/GetPolicyRolesById/" + _sarpara.Id);

                string valorrespuesta = "";
                if (result.IsSuccessStatusCode)
                {
                    valorrespuesta = await(result.Content.ReadAsStringAsync());
                    _Policy        = JsonConvert.DeserializeObject <PolicyRolesDTO>(valorrespuesta);
                }

                if (_Policy == null)
                {
                    _Policy = new PolicyRolesDTO();
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                throw ex;
            }



            return(PartialView(_Policy));
        }
Example #2
0
        public async Task <ActionResult <PolicyRoles> > SavePolicyRoles([FromBody] PolicyRolesDTO _PolicyRolesp)
        {
            PolicyRoles _PolicyRoles = _PolicyRolesp;

            try
            {
                string     baseadress = config.Value.urlbase;
                HttpClient _client    = new HttpClient();
                _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
                var result = await _client.GetAsync(baseadress + "api/PolicyRoles/GetPolicyRolesById/" + _PolicyRoles.Id);

                string valorrespuesta = "";
                _PolicyRoles.UsuarioModificacion = HttpContext.Session.GetString("user");
                if (result.IsSuccessStatusCode)
                {
                    valorrespuesta = await(result.Content.ReadAsStringAsync());
                    _PolicyRoles   = JsonConvert.DeserializeObject <PolicyRoles>(valorrespuesta);
                }

                if (_PolicyRoles == null)
                {
                    _PolicyRoles = new Models.PolicyRoles();
                }



                if (_PolicyRolesp.Id.ToString() == "00000000-0000-0000-0000-000000000000")

                {
                    _PolicyRoles.UsuarioCreacion = HttpContext.Session.GetString("user");
                    var insertresult = await Insert(_PolicyRolesp);
                }
                else
                {
                    _PolicyRolesp.UsuarioCreacion = _PolicyRoles.UsuarioCreacion;
                    var updateresult = await Update(_PolicyRolesp.Id, _PolicyRolesp);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                throw ex;
            }

            return(Json(_PolicyRoles));
        }