コード例 #1
0
        public ActionResult Delete(Guid id)
        {
            var deleteStatusModelItems = new List <DeleteStatusModel>();

            var role         = _RoleManager.FindById(id.ToString());
            var deleteResult = _RoleManager.Delete(role);

            if (deleteResult.Succeeded)
            {
                deleteStatusModelItems.Add(new DeleteStatusModel()
                {
                    OperationMessage = "", OperationStatus = true
                });
            }
            else
            {
                foreach (var errorItem in deleteResult.Errors)
                {
                    deleteStatusModelItems.Add(new DeleteStatusModel()
                    {
                        OperationMessage = errorItem, OperationStatus = false
                    });
                }
            }

            return(Json(deleteStatusModelItems));
        }
コード例 #2
0
ファイル: RolesController.cs プロジェクト: vlarok/web
        public ActionResult DeleteConfirmed(int id)
        {
            var role = _roleManager.FindById(id);

            _roleManager.Delete(role);
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public JsonResult Delete(string model)
        {
            string roleName = string.Empty;

            try
            {
                RoleManagementViewModel role = JsonConvert.DeserializeObject <RoleManagementViewModel>(model);
                var roleToDelete             = _roleManager.Roles.Where(r => r.Id == role.RoleId).First();
                if (roleToDelete != null)
                {
                    roleName = roleToDelete.Name;
                    IdentityResult result = _roleManager.Delete(roleToDelete);
                    if (result == IdentityResult.Success)
                    {
                        Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
                        return(Json("success", JsonRequestBehavior.AllowGet));
                    }
                }
                throw new System.Exception("Role does not exist.");
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                return(Json("Delete role '" + roleName + "' fails. " + ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #4
0
        public void ApplicationRoleManager_AddUpdateDelete_Test()
        {
            var _roleTst = new ApplicationRole()
            {
                Id = "tst", Name = "Test"
            };

            _sut.Create(_roleTst);
            var _role = _sut.FindByName(_roleTst.Name);

            Assert.AreEqual(_role.Id, _roleTst.Id);
            var _roleById = _sut.FindById(_roleTst.Id);

            Assert.AreEqual(_roleById.Name, _roleTst.Name);
            _roleTst.Name = "Tests";
            _sut.Update(_roleTst);
            _roleById = _sut.FindById(_roleTst.Id);
            Assert.AreEqual(_roleById.Name, _roleTst.Name);
            _sut.Delete(_roleTst);
            _roleById = _sut.FindById(_roleTst.Id);
            Assert.IsNull(_roleById);
            //Task.Run(async () =>
            //{
            //}).GetAwaiter().GetResult();
        }
コード例 #5
0
        public virtual ActionResult Delete(DeleteConfirmViewModel model)
        {
            var role = _roleManager.Roles.FirstOrDefault(x => x.Id == model.Id);

            _roleManager.Delete(role);

            return(RedirectToAction(MVC.Account.Roles.List()));
        }
コード例 #6
0
ファイル: RoleController.cs プロジェクト: testpasha777/Rent
        public ActionResult DeleteConfirmed(string id)
        {
            var role = roleMnager.FindById(id);

            roleMnager.Delete(role);

            return(RedirectToAction("Index"));
        }
コード例 #7
0
 public static IEnumerable <IdentityResult> CreateAll(ApplicationDbContext context, ApplicationRoleManager roleManager)
 {
     if (roleManager != null && roleManager.RoleExists("ListManagers"))
     {
         roleManager.Delete(roleManager.Roles.First(r => r.Name == "ListManagers"));
     }
     return(CreateAll(context, roleManager, Administrators, Editors, ListManagers, Users, Public, Guests));
 }
コード例 #8
0
        public override void PerformModification(IDictionary <string, ContentModifierForm> modifierForm, ApplicationRole datum,
                                                 DatumModifyOperation operation,
                                                 Type datumType)
        {
            IdentityResult ir    = null;
            var            hasOp = false;

            if (operation.IsCreateOrUpdateOperation())
            {
                var f = modifierForm[FORM_KEY].DirectCastTo <RoleDatumModifierForm>();
                datum.Name        = f.Name;
                datum.Description = f.Description;
                ir = operation.IsCreateOperation() ? _roleMgr.Create(datum) : _roleMgr.Update(datum);
                if (ir.Succeeded)
                {
                    foreach (var perm in _permMgr.AllPermissions)
                    {
                        var pmap = _dbContext.ProtoPermissionsMaps
                                   .FirstOrDefault(x => x.RoleName == datum.Name && x.PermissionId == perm.Id);
                        if (pmap == null)
                        {
                            pmap = new ProtoPermissionsMap {
                                RoleName     = datum.Name,
                                PermissionId = perm.Id
                            };
                            _dbContext.ProtoPermissionsMaps.Add(pmap);
                        }
                        pmap.HasPermission = f.Permissions.Contains(perm.Id);
                    }
                    _dbContext.ThisDbContext().SaveChanges();
                }
                hasOp = true;
            }
            else if (operation.IsDeleteOperation())
            {
                ir = _roleMgr.Delete(datum);
                if (ir.Succeeded)
                {
                    var pmaps = _dbContext.ProtoPermissionsMaps.Where(x => x.RoleName == datum.Name).ToList();
                    foreach (var pmap in pmaps)
                    {
                        _dbContext.ProtoPermissionsMaps.Remove(pmap);
                    }
                }
                hasOp = true;
            }
            if (hasOp)
            {
                if (!ir.Succeeded)
                {
                    throw new Exception(string.Join("; ", ir.Errors));
                }
            }
        }
コード例 #9
0
        public ActionResult DeleteRoleConfirm(string id)
        {
            var deleteRole = RoleManager.Roles.SingleOrDefault(r => r.Id == id);

            if (deleteRole == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RoleManager.Delete(deleteRole);
            return(RedirectToAction("ManageRoles"));
        }
コード例 #10
0
        public void dvRoles_DeleteItem(string Id)
        {
            IdentityRole role = (from r in roleMgr.Roles
                                 where r.Id == Id
                                 select r).SingleOrDefault();
            IdentityResult result = roleMgr.Delete(role);

            if (result.Succeeded)
            {
                Reload();
            }
        }
コード例 #11
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void dvRoles_DeleteItem(string id)
        {
            IdentityRole role = (from r in roleManager.Roles
                                 where r.Id == id
                                 select r).SingleOrDefault();

            TryUpdateModel(role);
            IdentityResult result = roleManager.Delete(role);

            if (result.Succeeded)
            {
                Reload();
            }
        }
コード例 #12
0
        public void DeleteRole(string id, string userName)
        {
            var role = _roleManager.FindById(id);

            if (role != null)
            {
                _roleManager.Delete(role);
            }

            try {
                var roles = context.Roles.Include("Actions").Where(t => t.IsActive == true && t.IsDeleted != true && t.IsDraft == false).ToList();
                HttpContext.Current.Cache["roles"] = roles;
            } catch (Exception exc) {
                ErrorLog(exc);
            }
        }