コード例 #1
0
 public IEnumerable <User> Get()
 {
     using (LossContext db = new LossContext())
     {
         return(db.Users.ToList());
     }
 }
コード例 #2
0
 public User Add(User user)
 {
     using (LossContext db = new LossContext())
     {
         var result = db.Users.Add(user);
         db.SaveChanges();
         return(result);
     }
 }
コード例 #3
0
 public User GetUserByUsername(string username)
 {
     using (LossContext db = new LossContext())
     {
         foreach (User user in db.Users)
         {
             if (user.Username == username)
             {
                 return(user);
             }
         }
         return(null);
     }
 }
コード例 #4
0
 public void Login(User user)
 {
     using (LossContext db = new LossContext())
     {
         var foundUser = this.GetUserByUsername(user.Username);
         if (foundUser != null)
         {
             if (user.Password != foundUser.Password)
             {
                 throw new System.ArgumentException("Invalid username or password");
             }
         }
         else
         {
             throw new System.ArgumentException("Invalid username or password");
         }
     }
 }