示例#1
0
        private RoleGridModel SetUpRolesGridModel()
        {
            var gridModel = new RoleGridModel();

            SetUpRolesGrid(gridModel.RoleGrid);
            return(gridModel);
        }
示例#2
0
        public ActionResult Create(RoleGridModel role)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));

                    if (!roleManager.RoleExists(role.Name))
                    {
                        IdentityRole   newRole = new IdentityRole(role.Name);
                        IdentityResult result  = roleManager.Create(newRole);
                        if (result != null && !result.Succeeded)
                        {
                            ViewData["EditError"] = "Password could not set. \n";
                        }
                    }
                    else
                    {
                        ViewData["EditError"] = "Role is already exist.";
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }
            return(PartialView("GridRolePartial"));
        }
示例#3
0
 public ActionResult Edit(RoleGridModel role)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var          roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));
             IdentityRole idRole      = roleManager.FindById(role.Id);
             idRole.Name = role.Name;
             IdentityResult result = roleManager.Update(idRole);
             if (result != null && !result.Succeeded)
             {
                 ViewData["EditError"] = "Password could not set. \n";
             }
         }
         catch (DbEntityValidationException e)
         {
             string errorStr = string.Empty;
             foreach (var eve in e.EntityValidationErrors)
             {
                 errorStr = string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                 foreach (var ve in eve.ValidationErrors)
                 {
                     errorStr += string.Format("\n - Property: \"{0}\", Error: \"{1}\"",
                                               ve.PropertyName, ve.ErrorMessage);
                 }
             }
             ViewData["EditError"] = errorStr;
         }
         catch (Exception e)
         {
             ViewData["EditError"] = e.Message;
         }
     }
     else
     {
         ViewData["EditError"] = "Please, correct all errors.";
     }
     return(PartialView("GridRolePartial"));
 }