public Boolean CreateUser(ref User user, ref string message) { message = String.Empty; UserBDO userBDO = new UserBDO(); TranslateUserDTOToUserBDO(user, userBDO); return userLogic.CreateUser(ref userBDO, ref message); }
public User GetUser(string username) { UserBDO ubdo = new UserBDO(); ubdo = userLogic.GetUser(username); User u = new User(); TranslateUserBDOToUserDTO(ubdo, u); return u; }
public List<User> GetAllUsers() { List<UserBDO> userBDOList = userLogic.GetAllUsers(); List<User> allUsers = new List<User>(); foreach (UserBDO userBDO in userBDOList) { User user = new User(); TranslateUserBDOToUserDTO(userBDO, user); allUsers.Add(user); } return allUsers; }
private void butLogin_Click(object sender, EventArgs e) { try { IUserService userService = new UserService(); string message = String.Empty; if (txtPassword.Text.Equals("Enter Password") || txtPassword.Text.Equals(String.Empty) || txtUsername.Text.Equals("Enter Username") || txtUsername.Text.Equals(String.Empty)) { MessageBox.Show(this, "Username and Password is Required", "Required Fields"); } else { if (userService.AuthenticateUser(txtUsername.Text, txtPassword.Text, ref message)) { User u = new User(); u = userService.GetUser(txtUsername.Text); LoggedUser lu = new LoggedUser(); lu.UserId = u.UserId; lu.UserName = u.UserName; lu.LastName = u.LastName; lu.FirstName = u.FirstName; lu.MiddleName = u.MiddleName; lu.UserType = u.UserTypeCode; GlobalClass.UserLoggedIn = true; GlobalClass.user = lu; GlobalClass.currentsy = userService.GetCurrentSy(); GlobalClass.userTypeCode = lu.UserType; ILogService logService = new LogService(); string json = JsonConvert.SerializeObject(lu); Log log = new Log { CLUD = "L", LogDate = DateTime.Now, TableName = "Users", UserId = GlobalClass.user.UserId, UserName = GlobalClass.user.UserName, PassedData = json }; logService.AddLogs(log); Close(); } else MessageBox.Show(this, message, "Login Failed"); } }catch(Exception ex) { MessageBox.Show("Unable to Establish the network connection. Please check if network is connected.", "LogIn Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
public void TranslateUserBDOToUserDTO(UserBDO userBDO, User user) { user.UserId = userBDO.UserId; user.FirstName = userBDO.FirstName; user.LastName = userBDO.LastName; user.MiddleName = userBDO.MiddleName; user.UserName = userBDO.UserName; user.Password = userBDO.Password; user.UserTypeCode = userBDO.UserType.UserTypeCode; }
public void TranslateUserDTOToUserBDO(User user, UserBDO userBDO) { UserTypeBDO ut = new UserTypeBDO(); ut.UserTypeCode = user.UserTypeCode; userBDO.UserId = user.UserId; userBDO.FirstName = user.FirstName; userBDO.LastName = user.LastName; userBDO.MiddleName = user.MiddleName; userBDO.UserName = user.UserName; userBDO.Password = user.Password; userBDO.UserType = ut; }
private void SaveUser() { try { Boolean ret = false; string message = String.Empty; if (Op.Equals("edit")) { if (!ComparePasswords(oldPassword, txtOldPWD.Text)) { message = "Passwords do not match"; MessageBox.Show("Incorrect old password entered", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (!txtPassword.Text.ToString().Equals(txtRetypePWD.Text.ToString())) { message = "Passwords did not match"; MessageBox.Show("Password did not match"); return; } else { string hashPWD = GenerateKeyHash(txtPassword.Text); IUserService userService = new UserService(); User user = new User() { UserName = txtUsername.Text, FirstName = txtFirstName.Text, LastName = txtLastName.Text, MiddleName = txtMiddleName.Text, Password = hashPWD, UserTypeCode = cmbUserRole.SelectedValue.ToString() }; if (Op.Equals("edit")) { user.UserId = SelectedUser.UserId; if (!String.IsNullOrEmpty(txtPassword.Text)) user.Password = hashPWD; else user.Password = oldPassword; ret = userService.UpdateUser(ref user, ref message); Log("U", "Users", user); } else { ret = userService.CreateUser(ref user, ref message); Log("C", "Users", user); } } MessageBox.Show("Saved Successfully!"); Close(); } catch (Exception ex) { MessageBox.Show("Error: " + ex.ToString()); } }
private void gvUser_SelectionChanged(object sender, EventArgs e) { int selectedIndex = gvUser.CurrentRow.Index; if (selectedIndex >= 0) { string uID = gvUser.Rows[selectedIndex].Cells["UserId"].Value.ToString(); List<User> item = new List<User>(); item = userList.FindAll(x => x.UserId.ToString() == uID); userSelected = new User(); userSelected = (User)item[0]; } }