Exemplo n.º 1
0
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
              {
            RoleDataStore roleStore = new RoleDataStore(transaction);

            //Find the roles
            Role[] roles = new Role[roleNames.Length];
            for (int i = 0; i < roleNames.Length; i++)
            {
              //Find the role
              Role role = roleStore.FindByName(ApplicationName, roleNames[i]);
              if (role == null)
            throw new RoleNotFoundException(roleNames[i]);

              roles[i] = role;
            }

            UserInRoleDataStore usersInRolesStore = new UserInRoleDataStore(transaction);
            foreach (string userName in usernames)
            {
              foreach (Role role in roles)
              {
            UserInRole userInRole = new UserInRole(ApplicationName, userName, role.Name);

            usersInRolesStore.Insert(userInRole);
              }
            }

            transaction.Commit();
              }
        }
Exemplo n.º 2
0
        public ActionResult EditRole(int id)
        {
            RoleDataStore    Obj = new RoleDataStore();
            SA_RoleViewModel obj = Obj.GetRoleByid(id);

            return(View("add-role", obj));
        }
Exemplo n.º 3
0
        public ActionResult Role()
        {
            RoleDataStore Obj = new RoleDataStore();

            // List<SA_Role> RoleList = Obj.GetRoleList();
            return(View("Role"));
        }
Exemplo n.º 4
0
        public JsonResult RoleList()
        {
            RoleDataStore           Obj      = new RoleDataStore();
            List <SA_RoleViewModel> RoleList = Obj.GetRoleList();

            return(Json(new { data = RoleList }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 5
0
        public ActionResult DeleteRole(int id)
        {
            RoleDataStore Obj = new RoleDataStore();

            if (Obj.DeleteRole(id) == true)
            {
                return(View("role"));
            }
            else
            {
                return(View("ErrorEventArgs"));
            }
        }
Exemplo n.º 6
0
        public ActionResult SaveRole(SA_RoleViewModel UserRole)
        {
            UserRole.CreatedTime = DateTime.Now.ToString();
            RoleDataStore Obj = new RoleDataStore();

            if (UserRole.id == 0)
            {
                Obj.AddRole(UserRole);
            }
            else
            {
                Obj.EditRole(UserRole);
            }
            return(RedirectToAction("Role"));
        }
Exemplo n.º 7
0
 public RoleController(IUserContext user, ILogger <RoleController> logger, RoleDataStore store)
 {
     _store = store;
 }
Exemplo n.º 8
0
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
              {
            RoleDataStore roleStore = new RoleDataStore(transaction);
            UserInRoleDataStore userInRoleDataStore = new UserInRoleDataStore(transaction);

            //Find role
            Role role = roleStore.FindByName(ApplicationName, roleName);
            if (role == null)
              throw new RoleNotFoundException(roleName);

            IList<UserInRole> listUserInRole = userInRoleDataStore.FindForRole(ApplicationName, roleName);

            if (throwOnPopulatedRole && listUserInRole.Count > 0)
              throw new System.Configuration.Provider.ProviderException("Cannot delete a populated role.");

            foreach (UserInRole ur in listUserInRole)
              userInRoleDataStore.Delete(ur.Id);

            roleStore.Delete(role.Id);

            transaction.Commit();
              }

              return true;
        }
Exemplo n.º 9
0
        public override void CreateRole(string roleName)
        {
            //Check required for MSDN
              if (roleName == null || roleName == "")
            throw new System.Configuration.Provider.ProviderException("Role name cannot be empty or null.");
              if (roleName.IndexOf(',') > 0)
            throw new ArgumentException("Role names cannot contain commas.");
              if (RoleExists(roleName))
            throw new System.Configuration.Provider.ProviderException("Role name already exists.");

              using (TransactionScope transaction = new TransactionScope(mConfiguration))
              {
            RoleDataStore roleStore = new RoleDataStore(transaction);

            roleStore.Insert(new Role(ApplicationName, roleName));

            transaction.Commit();
              }
        }
Exemplo n.º 10
0
 public override bool RoleExists(string roleName)
 {
     using (TransactionScope transaction = new TransactionScope(mConfiguration))
       {
     RoleDataStore store = new RoleDataStore(transaction);
     if (store.FindByName(ApplicationName, roleName) != null)
       return true;
     else
       return false;
       }
 }
Exemplo n.º 11
0
        public override string[] GetAllRoles()
        {
            List<string> rolesNames = new List<string>();

              using (TransactionScope transaction = new TransactionScope(mConfiguration))
              {
            RoleDataStore roleDataStore = new RoleDataStore(transaction);

            IList<Role> list = roleDataStore.FindAll(ApplicationName);

            foreach (Role ur in list)
            {
              rolesNames.Add(ur.Name);
            }
              }

              return rolesNames.ToArray();
        }