0
最近ログインしたユーザーのリストを取得したいのですが、最近asp.netコアMVCにログインしたユーザーのリストを取得するにはどうすればよいですか?asp.netコアMVCで最近ログインしたユーザーのリストを取得するには?
最近ログインしたユーザーのリストを取得したいのですが、最近asp.netコアMVCにログインしたユーザーのリストを取得するにはどうすればよいですか?asp.netコアMVCで最近ログインしたユーザーのリストを取得するには?
あなたは、モデルクラスを作成することができます。
だから、ユーザーがログインした時にエントリを行い、いくつかのサービスを必要とするpublic class LoginEntry
{
[Key]
public string EntryID { get; set; }
public string UserID { get; set; }
public ApplicationUser User { get; set; } //represents the user who was logged
public DateTime? TimeOfLastLogin { get; set; } //time when the user logged last time
}
:あなたは、ユーザが例えば、からログインしているDoEntyメソッドを呼び出すことができます
public class LoginEntryService
{
public void DoEntry(ApplicationUser user)
{
var entry = dbcontext.LoginEntries.SingleOrDefault(e => e.UserID == userID);
if (entry == null) //if Entry for the user does not exist then create it
entry = new LoginEntry() {UserID = user.ID};
entry.TimeOfLastLogin = DateTime.UtcNow; //update the last login time
if (entry.ID == null)
dbcontext.LoginEntries.Add(entry);
dbcontext.SaveChanges();
}
}
、コントローラまたはユーザリポジトリのインスタンス