public IEnumerable<hunt> GetTreasureHuntsForParticularUser(user user) { using (var context = new TreasureHuntEntities()) { if (user == null) return null; var returnedHuntIds = context.userhunts.Where(c => c.UserId == user.UserId).Select(s => s.HuntId).ToList(); returnedHuntIds.ForEach(e => context.ObjectStateManager.ChangeObjectState(e, System.Data.EntityState.Detached)); List<hunt> returnedListOfHunts = new List<hunt>(); foreach (var huntId in returnedHuntIds) { var hunt = context.hunts.Where(c => c.HuntId == huntId).Single(); context.ObjectStateManager.ChangeObjectState(hunt, System.Data.EntityState.Detached); returnedListOfHunts.Add(hunt); } return returnedListOfHunts; } }
/// <summary> /// Deprecated Method for adding a new object to the users EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddTousers(user user) { base.AddObject("users", user); }
/// <summary> /// Create a new user object. /// </summary> /// <param name="userId">Initial value of the UserId property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="email">Initial value of the Email property.</param> /// <param name="password">Initial value of the Password property.</param> public static user Createuser(global::System.Int64 userId, global::System.String name, global::System.String email, global::System.String password) { user user = new user(); user.UserId = userId; user.Name = name; user.Email = email; user.Password = password; return user; }
/// <summary> /// Method that updates the login password associated with a given user. /// </summary> /// <param name="currentUser"></param> /// <param name="newPassword"></param> public void updateUserPassword(user currentUser, String newPassword) { using (var context = new TreasureHuntEntities()) { var userToChange = context.users.Where(c => c.UserId == currentUser.UserId).Single(); userToChange.Password = newPassword; context.SaveChanges(); context.ObjectStateManager.ChangeObjectState(userToChange, System.Data.EntityState.Modified); } }
/// <summary> /// Method that saves a new user into the 'users' table. /// </summary> /// <param name="newUser"></param> /// <returns></returns> public long SaveUser(user newUser) { using (var context = new TreasureHuntEntities()) { context.users.AddObject(newUser); context.SaveChanges(); context.ObjectStateManager.ChangeObjectState(newUser, System.Data.EntityState.Added); return newUser.UserId; } }
/// <summary> /// Method that returns all of the securityquestion data associated with a given user. /// </summary> /// <param name="user"></param> /// <returns></returns> public securityquestion getUserSecurityQuestion(user user) { using (var context = new TreasureHuntEntities()) { if (user == null) return null; //Grab the user's securityquestionId var returnedUserSecurityQuestionId = context.usersecurityquestions.Where(c => c.UserId == user.UserId).Select(s => s.SecurityQuestionId).Single(); context.ObjectStateManager.ChangeObjectState(returnedUserSecurityQuestionId, System.Data.EntityState.Detached); //Grab the security question associated with this id. var returnedQuestion = context.securityquestions.Where(c => c.SecurityQuestionId == returnedUserSecurityQuestionId).Single(); context.ObjectStateManager.ChangeObjectState(returnedQuestion, System.Data.EntityState.Detached); return returnedQuestion; } }
/// <summary> /// Method that returns the securityquestion answer associated with a given user. /// </summary> /// <param name="currentUser"></param> /// <returns></returns> public usersecurityquestion getUserSecurityAnswer(user currentUser) { using (var context = new TreasureHuntEntities()) { if (currentUser == null) return null; var returnedUserSecurityQuestionDetails = context.usersecurityquestions.Where(c => c.UserId == currentUser.UserId).Single(); context.ObjectStateManager.ChangeObjectState(returnedUserSecurityQuestionDetails, System.Data.EntityState.Detached); return returnedUserSecurityQuestionDetails; } }
/// <summary> /// Method that returns the userrole data associated with the given user. /// </summary> /// <param name="user"></param> /// <returns></returns> public userrole GetUserRole(user user) { using (var context = new TreasureHuntEntities()) { var returnedUserRole = context.userroles.Where(c => c.UserId == user.UserId).Single(); context.ObjectStateManager.ChangeObjectState(returnedUserRole, System.Data.EntityState.Detached); return returnedUserRole; } }
/// <summary> /// Method that returns a list of treasure hunts for a given user. /// </summary> /// <param name="user"></param> /// <returns></returns> public IEnumerable<hunt> GetTreasureHuntsForParticularUser(user user) { using (var context = new TreasureHuntEntities()) { if (user == null) return null; //Grab of all HuntIds associated with the given user. var returnedHuntIds = context.userhunts.Where(c => c.UserId == user.UserId).Select(s => s.HuntId).ToList(); returnedHuntIds.ForEach(e => context.ObjectStateManager.ChangeObjectState(e, System.Data.EntityState.Detached)); List<hunt> returnedListOfHunts = new List<hunt>(); //For each of these ids foreach (var huntId in returnedHuntIds) { //Add to a list the hunt associated with this id. var hunt = context.hunts.Where(c => c.HuntId == huntId).Single(); context.ObjectStateManager.ChangeObjectState(hunt, System.Data.EntityState.Detached); returnedListOfHunts.Add(hunt); } //Return this list. return returnedListOfHunts; } }