public void NewUserSession() { Debug.WriteLine("USERACCESS: NewUserSession called."); using (FWFCUsersdbEntities context = new FWFCUsersdbEntities()) { if (context.Users.Any(c => c.UserName == thisUser.UserName)) { Debug.WriteLine("USER: User found in DB!"); var currentUser = context.Users.Where(c => c.UserName == thisUser.UserName).SingleOrDefault(); if (currentUser.Password == thisUser.Password) { Debug.WriteLine("USER: Password Match!"); currentUser.UserStatus = "LOGGEDIN"; currentUser.LastAccessDateTime = DateTime.Now; context.AttemptSaveChanges(); RetrieveAllUserInfoFromDB(); } else { ClearAllDBRelation(); } } else { ClearAllDBRelation(); } } }
public void UpdateUserInfo() { using (FWFCUsersdbEntities context = new FWFCUsersdbEntities()) { User updatingUser = context.Users.Where(c => c.UserID == thisUser.UserID).SingleOrDefault(); if (updatingUser != null) { Debug.WriteLine("USER: User Found: Updating DB with Basic Info"); updatingUser.ModifiedDateTime = DateTime.Now; updatingUser.UserName = thisUser.UserName; updatingUser.First_Name = thisUser.First_Name; updatingUser.Last_Name = thisUser.Last_Name; updatingUser.Password = thisUser.Password; updatingUser.isAdmin = thisUser.isAdmin; Role updatingUserRole = context.Roles.Where(c => c.FK_UserID == updatingUser.UserID).SingleOrDefault(); if (updatingUserRole != null) { AssociateRoleInfo(updatingUserRole); } else { Debug.WriteLine("ROLE: No Existing Roles Found! Creating New Role record in DB."); thisUserRole.FK_UserID = updatingUser.UserID; context.Roles.Add(thisUserRole); } context.AttemptSaveChanges(); } } }
public void LogOut() { Debug.WriteLine("USERACCESS: LogOut called."); using (FWFCUsersdbEntities context = new FWFCUsersdbEntities()) { var logoutUser = context.Users.Where(c => c.UserName == this.thisUser.UserName).FirstOrDefault(); if (!(logoutUser == null)) { Debug.WriteLine("USERACCESS: Attempting to Log Out " + logoutUser.UserName); logoutUser.UserStatus = "LOGOUT"; } context.AttemptSaveChanges(); ClearAllDBRelation(); } }
public void UpdatePassword() { using (FWFCUsersdbEntities context = new FWFCUsersdbEntities()) { var updatePasswordFocusUser = context.Users.Where(c => c.UserID == thisUser.UserID).SingleOrDefault(); if (updatePasswordFocusUser != null) { Debug.WriteLine("USER: User Found! Updating Password."); updatePasswordFocusUser.Password = thisUser.Password; } else { Debug.WriteLine("USER: User Not Found in DB! Unable to update Password."); } context.AttemptSaveChanges(); } }
private void SaveNewUserToDB() { using (FWFCUsersdbEntities context = new FWFCUsersdbEntities()) { thisUser.CreatedDateTime = DateTime.Now; thisUser.ModifiedDateTime = DateTime.Now; thisUser.UserStatus = "NEW"; context.Users.Add(thisUser); context.AttemptSaveChanges(); thisUser = context.Users.Where(c => c.UserName == thisUser.UserName).SingleOrDefault(); if (thisUser != null) { Debug.WriteLine("USER: New User's DB UserID = " + thisUser.UserID); } else { Debug.WriteLine("USER: There has been an error associating a new UserID!"); } } }