public static void AddRole(string[] arrId) { foreach (string Id in arrId) { Guid rId = new Guid(Id); Role role = RoleNotOfUserCollection.Where(r => r.Id == rId).Single(); RoleList.Add(role); RoleNotOfUserCollection.Remove(role); RoleOfUserList.Add(new UserInRole { UserId = Args.User.Id, RoleId = rId }); } }
public static void RoleDelete(string[] arrId) { foreach (string id in arrId) { Guid idRole = new Guid(id); Role role = RoleList.Where(u => u.Id == idRole).Single(); RoleList.Remove(role); UserInRole roleOfUser = RoleOfUserList.Where(u => u.RoleId == idRole && u.UserId == Args.User.Id).Single(); RoleOfUserList.Remove(roleOfUser); RoleNotOfUserCollection.Add(role); RoleNotOfUserList.Add(roleOfUser); } }
public static void Save() { //list of user added IEnumerable <UserInRole> addedUsers = RoleOfUserList.Except(CopyOfRoleOfUserList, new UserInRoleEqualityComparer()); IEnumerable <UserInRole> deletedUsers = CopyOfRoleOfUserList.Except(RoleOfUserList, new UserInRoleEqualityComparer()); foreach (UserInRole u in addedUsers) { CopyOfRoleOfUserList.AddDB(u); } List <UserInRole> list = deletedUsers.ToList <UserInRole>(); for (int i = 0; i < list.Count; i++) { UserInRole u = list[i]; CopyOfRoleOfUserList.RemoveDB(u); } }