public IEnumerable <User> Get() { using (LossContext db = new LossContext()) { return(db.Users.ToList()); } }
public User Add(User user) { using (LossContext db = new LossContext()) { var result = db.Users.Add(user); db.SaveChanges(); return(result); } }
public User GetUserByUsername(string username) { using (LossContext db = new LossContext()) { foreach (User user in db.Users) { if (user.Username == username) { return(user); } } return(null); } }
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"); } } }