按日期降序获取被禁止用户的列表

发布于 2024-10-19 10:33:33 字数 452 浏览 1 评论 0原文

我正在做这样的事情来获取所有已被阻止的用户的列表:

public IQueryable<Aspnet_User> GetBannedUsers()
{
    return db.Aspnet_Memberships.Where(x => x.IsApproved == false).Select(x => x.Aspnet_User);
}

我这样做是为了阻止用户:

MembershipUser user = Membership.GetUser(username);
if (user != null)
{
    user.IsApproved = isApproved;
    Membership.UpdateUser(user);
}

我如何获取按被禁止日期排序的被禁止用户的列表。 最近被禁止的应该排在第一位。

Im doing something like this to get a list of all users that have been blocked:

public IQueryable<Aspnet_User> GetBannedUsers()
{
    return db.Aspnet_Memberships.Where(x => x.IsApproved == false).Select(x => x.Aspnet_User);
}

Im doing this to block users:

MembershipUser user = Membership.GetUser(username);
if (user != null)
{
    user.IsApproved = isApproved;
    Membership.UpdateUser(user);
}

how can i get the list of banned users ordered by date they were banned.
most recently banned should be first.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦萦几度 2024-10-26 10:33:33

默认情况下,asp.net 成员资格不存储此日期,因此您必须使用解决方法。一个巧妙的方法是引入您自己的表,但我建议滥用 LastLoginDate。只要用户未正确登录,默认机制就不会触及此日期(您的 !isApproved 将阻止发生这种情况)。

修改代码以阻止用户:

MembershipUser user = Membership.GetUser(username);             
if (user != null)             
{                 
  user.IsApproved = isApproved;
  user.LastLoginDate = DateTime.Now;
  Membership.UpdateUser(user);             
}

按禁止日期排序的代码,从 @Femaref 的答案复制粘贴:

public IQueryable<Aspnet_User> GetBannedUsers()            
{ 
  return db.Aspnet_Memberships          
    .Where(x => x.IsApproved == false)                        
    .OrderByDescening(x => x.LastLoginDate) 
    .Select(x => x.Aspnet_User);
}

By default, asp.net membership does not store this date, so you'll have to use a workaround. A neat approach would be to introduce your own table, but I suggest abusing the LastLoginDate. The default mechanism will not touch this date as long as the user doesn't login properly (which your !isApproved will prevent from happening).

Modified code to block user:

MembershipUser user = Membership.GetUser(username);             
if (user != null)             
{                 
  user.IsApproved = isApproved;
  user.LastLoginDate = DateTime.Now;
  Membership.UpdateUser(user);             
}

Code to sort on banned date, copy pasted from @Femaref's answer:

public IQueryable<Aspnet_User> GetBannedUsers()            
{ 
  return db.Aspnet_Memberships          
    .Where(x => x.IsApproved == false)                        
    .OrderByDescening(x => x.LastLoginDate) 
    .Select(x => x.Aspnet_User);
}
原野 2024-10-26 10:33:33
public IQueryable<Aspnet_User> GetBannedUsers()
{
    return db.Aspnet_Memberships
             .Where(x => x.IsApproved == false)
             .OrderByDescening(x => x.BannedDate) //adjust property here
             .Select(x => x.Aspnet_User);
}
public IQueryable<Aspnet_User> GetBannedUsers()
{
    return db.Aspnet_Memberships
             .Where(x => x.IsApproved == false)
             .OrderByDescening(x => x.BannedDate) //adjust property here
             .Select(x => x.Aspnet_User);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文