/// <summary> /// Converts a UserSM to a UserDM /// </summary> /// <param name="human">UserSM human</param> /// <returns>UserDM</returns> private UserDM Map(UserSM human) //Converts for use in the Data Layer { UserDM hm = new UserDM(); hm.UserName = human.UserName; hm.Password = human.Password.CurrentPassword; hm.SecLev = human.SecLev; hm.UserId = human.UserId.ToString(); return(hm); }
/// <summary> /// Converts UserDM to UserSM for use on the Logic Layer /// </summary> /// <param name="human">UserDM human</param> /// <returns>UserSM</returns> private UserSM Map(UserDM human) // Converts for user in the Logic/Presentation Layer { UserSM hm = new UserSM(); hm.UserName = human.UserName; hm.Password.CurrentPassword = human.Password; hm.SecLev = human.SecLev; hm.UserId = Convert.ToInt32(human.UserId); return(hm); }
/// <summary> /// Takes User input to update User in database. /// </summary> /// <param name="user">UserSM user</param> public void EditUserById(UserSM user) { try { userData.EditUserById(Map(user)); logs.LogError("Event", "User was successfully able to update", "Class:UserLogic, Method:EditUser"); } catch (Exception c) { logs.LogError("Error", "User was unable to update", "Class:UserLogic, Method:EditUser"); } }
/// <summary> /// Compares Newly Input password and Confirmation Password and changes the password in the database /// </summary> /// <param name="pass">PasswordSM pass</param> public void UpdatePassword(UserSM person) { UserSM guy = GetUserById(person.UserId); if (person.Password.NewPassword == person.Password.ConfirmPassword) { if (hash.GetHash(person.Password.CurrentPassword) == guy.Password.CurrentPassword) { guy.Password.CurrentPassword = hash.GetHash(person.Password.NewPassword); userData.EditUserById(Map(guy)); } } }
/// <summary> /// Adds User to DataBase based on User input. /// </summary> /// <param name="user">UserSM user</param> public void CreateUser(UserSM user) { try { if (!CheckUsername(user.UserName)) { user.Password.CurrentPassword = hash.GetHash(user.Password.NewPassword); user.SecLev = "User"; userData.CreateUser(Map(user)); logs.LogError("Event", "a new user has been been added to database", "Class:UserLogic,Method:NewUser"); } } catch (Exception d) { logs.LogError("Error", "A new user has not been added to the database", "Class:UserLogic,Method:NewUser"); } }
public UserDM Map(UserSM human) { UserDM user = new UserDM(); user.userFirstName = human.userFirstName; user.userLastName = human.userLastName; user.userName = human.userName; user.userPassword = human.userPassword; user.ConfirmUserPassword = human.ConfirmUserPassword; user.userEmail = human.userEmail; user.ConfirmUserEmail = human.ConfirmUserEmail; user.userPhoneNumber = human.userPhoneNumber; user.userStreet = human.userStreet; user.userCity = human.userCity; user.userState = human.userState; user.userZipcode = human.userZipcode; user.userID = human.userID; user.userPosition = human.userPosition; return(user); }
/// <summary> /// Tests the User's Username and Password input and returns a bool if there's a match. /// </summary> /// <param name="tempUser">UserSM tempUser</param> /// <returns>bool</returns> public bool Login(UserSM tempUser) { try { if (tempUser.UserId > 0) { UserSM user = GetUserById(tempUser.UserId); if (tempUser.Password.CurrentPassword == user.Password.CurrentPassword) { logs.LogError("Event", "User was successfully able to Login", "Class:UserLogic, Method::Login"); return(true); } } } catch (Exception a) { logs.LogError("Error", "User was unable to Login", "Class:UserLogic, Method:Login"); } return(false); }
/// <summary> /// Locates a single user from the database based on Name /// </summary> /// <param name="user">UserSM user</param> /// <returns>UserSM</returns> public UserSM GetUser(UserSM user) { user.Password.CurrentPassword = hash.GetHash(user.Password.CurrentPassword); return(Map(userData.GetUser(Map(user)))); }
public void UpdateUser(UserSM user) { StoreData userData = new StoreData(); userData.UpdateUser(Map(user)); }
public void AddUser(UserSM human) { StoreData userData = new StoreData(); userData.CreateUser(Map(human)); }