コード例 #1
0
        public Task <long> UpdatePerfil(UpdatePerfilCommand command)
        {
            var requestUrl = CreateRequestUri(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                            $"{ResourcePerfil}/UpdatePerfil"));

            return(Post(requestUrl, command));
        }
コード例 #2
0
        public ActionResult Edit(string id, IFormCollection collection)
        {
            try
            {
                ListDictionary list            = new ListDictionary();
                var            responseModulos = ApiClientFactory.Instance.GetModuloAll();

                foreach (var modulo in responseModulos)
                {
                    var ListFuncionalidades = modulo.ListFuncionalidades.FirstOrDefault().NomFuncionalidade.Split(',');
                    var listValue           = ListFuncionalidades
                                              .Where(func => collection[modulo.NomModulo + func].ToString() == "on").ToList();
                    list.Add(modulo.NomModulo, string.Join(",", listValue));
                }

                var command = new UpdatePerfilCommand
                {
                    CodPerfil = id,
                    NomPerfil = collection["NomPerfil"].ToString(),
                    ListClaim = list
                };
                ApiClientFactory.Instance.UpdatePerfil(command);

                return(RedirectToAction(nameof(Index), new { crud = (int)EnumCrud.Updated }));
            }
            catch
            {
                return(View());
            }
        }
コード例 #3
0
        public async Task <ActionResult <bool> > UpdatePerfil(UpdatePerfilCommand command)
        {
            try
            {
                var result = false;

                var adminRole = await _roleManager.FindByIdAsync(command.CodPerfil);

                if (adminRole != null)
                {
                    adminRole.Name = command.NomPerfil;
                    var resRole = await _roleManager.UpdateAsync(adminRole);

                    var role   = _roleManager.Roles.Single(x => x.Id == command.CodPerfil);
                    var claims = _roleManager.GetClaimsAsync(role).Result;

                    foreach (var claim in claims)
                    {
                        var res = await _roleManager.RemoveClaimAsync(adminRole, claim);
                    }

                    foreach (DictionaryEntry claim in command.ListClaim)
                    {
                        var addClaim = new Claim(claim.Key.ToString(), claim.Value.ToString());
                        var res      = await _roleManager.AddClaimAsync(adminRole, addClaim);
                    }

                    result = true;
                }

                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }