2017-03-08 12 views

答えて

0

あなたは、モデルクラスを作成することができます。

だから、ユーザーがログインした時にエントリを行い、いくつかのサービスを必要とする
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(); 
    } 
} 

、コントローラまたはユーザリポジトリのインスタンス

関連する問題