Пример #1
0
        public async Task<ActionResult> ChangeRole(RoleModel model)
        {
            if (ModelState.IsValid)
            {
                IdentityResult result = IdentityResult.Failed();
                if (string.IsNullOrEmpty(model.Id))
                {
                    var role = new ApplicationRole {Id = Guid.NewGuid().ToString(), Name = model.Name, Description = model.Description};
                    result = await RoleManager.CreateAsync(role);
                }
                else
                {
                    ApplicationRole role = await RoleManager.FindByIdAsync(model.Id);
                    if (role != null)
                    {
                        role.Description = model.Description;
                        role.Name = model.Name;
                        result = await RoleManager.UpdateAsync(role);
                    }
                }

                if (result.Succeeded)
                    return RedirectToAction("Index");

                ModelState.AddModelError("", "Что-то пошло не так");
            }
            return View("ChangeRole", model);
        }
Пример #2
0
        public async Task<ActionResult> Edit(RoleModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationRole role = await RoleManager.FindByIdAsync(model.Id);
                if (role != null)
                {
                    role.Description = model.Description;
                    role.Name = model.Name;
                    IdentityResult result = await RoleManager.UpdateAsync(role);
                    if (result.Succeeded)
                        return RedirectToAction("Index");

                    ModelState.AddModelError("", "Что-то пошло не так");
                }
            }
            return View("ChangeRole", model);
        }