private void SaveExecute(object parameter) { try { DateTime dateOfBirth; if (!ValidationClass.JMBGisValid(User.JMBG, out dateOfBirth)) { MessageBox.Show("JMBG is not valid"); return; } int age = ValidationClass.CountAge(dateOfBirth); if (age < 18) { string str1 = string.Format("JMBG is not valid\nEmployee has " + "to be at least 18 years old"); MessageBox.Show(str1); return; } tblUser userInDb = userService.GetUserByUserName(User.Username); if (userInDb != null) { string str1 = string.Format("User with this username exists\n" + "Enter another username"); MessageBox.Show(str1); return; } userInDb = userService.GetUserByJMBG(User.JMBG); if (userInDb != null) { string str1 = string.Format("User with this JMBG exists\n" + "Enter another JMBG"); MessageBox.Show(str1); return; } var passwordBox = parameter as PasswordBox; var password = passwordBox.Password; string encryptedString = EncryptionHelper.Encrypt(password); User.Gender = Gender; User.MaritalStatus = MartialStatus; User.Password = encryptedString; User = userService.AddUser(User); Employee.SectorID = SelectedSector.SectorID; if (SelectedPosition != null) { Employee.PositionID = SelectedPosition.PositionID; } Employee.ProfessionalQualifications = Qualification; List <vwManager> managers = managerService.GetManagers(); var idList = managers.Select(item => item.ManagerID).ToList(); Random random = new Random(); int index = random.Next(idList.Count); int managerId = idList[index]; Employee.ManagerID = managerId; Employee.UserID = User.UserID; employeeService.AddEmployee(Employee); //string str = string.Format("You registered as employee\nYour manager is"); MessageBox.Show("You registered as employee"); LoginView loginView = new LoginView(); loginView.Show(); view.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void SaveExecute(object parameter) { try { DateTime dateOfBirth; if (!ValidationClass.JMBGisValid(User.JMBG, out dateOfBirth)) { MessageBox.Show("JMBG is not valid"); return; } int age = ValidationClass.CountAge(dateOfBirth); if (age < 18) { string str1 = string.Format("JMBG is not valid\nManager has to be at least 18 years old"); MessageBox.Show(str1); return; } tblUser userInDb = userService.GetUserByUserName(User.Username); if (userInDb != null) { string str1 = string.Format("User with this username exists\n" + "Enter another username"); MessageBox.Show(str1); return; } userInDb = userService.GetUserByJMBG(User.JMBG); if (userInDb != null) { string str1 = string.Format("User with this JMBG exists\n" + "Enter another JMBG"); MessageBox.Show(str1); return; } if (!ValidationClass.IsValidEmail(Manager.Email)) { MessageBox.Show("Email is not valid"); return; } tblManager managerInDb = managerService.GetManagerByEmail(Manager.Email); if (managerInDb != null) { string str1 = string.Format("Manager with this email exists\n" + "Enter another email"); MessageBox.Show(str1); return; } var passwordBox = parameter as PasswordBox; var password = passwordBox.Password; string encryptedString = EncryptionHelper.Encrypt(password); User.Gender = Gender; User.MaritalStatus = MartialStatus; User.Password = encryptedString; User = userService.AddUser(User); string reservePassword = string.Format("{0}WPF", Manager.ReservePassword); Manager.ReservePassword = reservePassword; Manager.UserID = User.UserID; managerService.AddManager(Manager); string str = string.Format("You registered as manager"); MessageBox.Show(str); view.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void SaveExecute(object parameter) { try { DateTime dateOfBirth; if (!ValidationClass.JMBGisValid(EmployeeToEdit.JMBG, out dateOfBirth)) { MessageBox.Show("JMBG is not valid"); return; } int age = ValidationClass.CountAge(dateOfBirth); if (age < 18) { string str1 = string.Format("JMBG is not valid\nEmployee has " + "to be at least 18 years old"); MessageBox.Show(str1); return; } tblUser userInDb = userService.GetUserByUserName(EmployeeToEdit.Username); if (userInDb != null) { if (EmployeeToEdit.Username.Equals(oldUserName)) { } else { string str1 = string.Format("User with this username exists\n" + "Enter another username"); MessageBox.Show(str1); return; } } userInDb = userService.GetUserByJMBG(EmployeeToEdit.JMBG); if (userInDb != null) { if (EmployeeToEdit.JMBG.Equals(oldJMBG)) { } else { string str1 = string.Format("User with this JMBG exists\n" + "Enter another JMBG"); MessageBox.Show(str1); return; } } var passwordBox = parameter as PasswordBox; var password = passwordBox.Password; string encryptedString = EncryptionHelper.Encrypt(password); tblUser newUser = CreateUser(EmployeeToEdit); newUser.Password = encryptedString; newUser = userService.AddUser(newUser); EmployeeToEdit.SectorID = SelectedSector.SectorID; if (SelectedPosition != null) { EmployeeToEdit.PositionID = SelectedPosition.PositionID; } EmployeeToEdit.ProfessionalQualifications = Qualification; tblEmployee newEmployee = CreateEmployee(EmployeeToEdit); newEmployee.UserID = newUser.UserID; newEmployee.ManagerID = EmployeeToEdit.ManagerID; newEmployee.IsNewRequest = true; newEmployee = employeeService.AddEmployee(newEmployee); tblRequestForChange newRequest = new tblRequestForChange(); newRequest.OldEmployeeID = oldEmployee.EmployeeID; newRequest.NewEmployeeID = newEmployee.EmployeeID; newRequest.CreationDate = DateTime.Today; employeeService.AddRequest(newRequest); //string str = string.Format("You registered as employee\nYour manager is"); MessageBox.Show("You send request for changes to your manager"); view.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void SaveExecute(object parameter) { try { DateTime dateOfBirth; if (!ValidationClass.JMBGisValid(User.JMBG, out dateOfBirth)) { MessageBox.Show("JMBG is not valid"); return; } int age = ValidationClass.CountAge(dateOfBirth); if (age < 18) { MessageBox.Show("JMBG is not valid\nAdmin has to be at least 18 years old"); return; } tblUser userInDb = userService.GetUserByUserName(User.Username); if (userInDb != null) { string str1 = string.Format("User with this username exists\n" + "Enter another username"); MessageBox.Show(str1); return; } userInDb = userService.GetUserByJMBG(User.JMBG); if (userInDb != null) { string str1 = string.Format("User with this JMBG exists\n" + "Enter another JMBG"); MessageBox.Show(str1); return; } var passwordBox = parameter as PasswordBox; var password = passwordBox.Password; string encryptedString = EncryptionHelper.Encrypt(password); User.Gender = Gender; User.MaritalStatus = MartialStatus; User.Password = encryptedString; User = userService.AddUser(User); DateTime today = DateTime.Now; Admin.ExpiryDate = today.AddDays(7); Admin.AdministratorType = SelctedType; Admin.UserID = User.UserID; adminService.AddAdmin(Admin); string str = string.Format("You added new admin of type {0}", SelctedType); MessageBox.Show(str); view.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void SaveExecute(object parameter) { try { DateTime dateOfBirth; if (!ValidationClass.JMBGisValid(ManagerToEdit.JMBG, out dateOfBirth)) { MessageBox.Show("JMBG is not valid"); return; } int age = ValidationClass.CountAge(dateOfBirth); if (age < 18) { string str1 = string.Format("JMBG is not valid\nManager has to be at least 18 years old"); MessageBox.Show(str1); return; } tblUser userInDb = userService.GetUserByUserName(ManagerToEdit.Username); if (userInDb != null) { if (userInDb.Username.Equals(oldUserName)) { } else { string str1 = string.Format("User with this username exists\n" + "Enter another username"); MessageBox.Show(str1); return; } } userInDb = userService.GetUserByJMBG(ManagerToEdit.JMBG); if (userInDb != null) { if (userInDb.JMBG.Equals(oldJMBG)) { } else { string str1 = string.Format("User with this JMBG exists\n" + "Enter another JMBG"); MessageBox.Show(str1); return; } } if (!ValidationClass.IsValidEmail(ManagerToEdit.Email)) { MessageBox.Show("Email is not valid"); return; } tblManager managerInDb = managerService.GetManagerByEmail(ManagerToEdit.Email); if (managerInDb != null) { if (managerInDb.Email.Equals(oldMail)) { } else { string str1 = string.Format("Manager with this email exists\n" + "Enter another email"); MessageBox.Show(str1); return; } } var passwordBox = parameter as PasswordBox; var password = passwordBox.Password; string encryptedString = EncryptionHelper.Encrypt(password); tblUser newUser = CreateUser(ManagerToEdit); newUser.Password = encryptedString; //string str3 = string.Format("{0} {1}", newUser.UserID,newUser.FirstName); //MessageBox.Show(str3); userService.EditUser(newUser); string reservePassword = string.Format("{0}WPF", Manager.ReservePassword); tblManager newManager = new tblManager(); newManager.ManagerID = ManagerToEdit.ManagerID; newManager.ReservePassword = reservePassword; newManager.Email = ManagerToEdit.Email; newManager.OfficeNumber = ManagerToEdit.OfficeNumber; managerService.EditManager(newManager); string str = string.Format("You succesfully edited you profile"); MessageBox.Show(str); //ManagerMainView managerMainView = new ManagerMainView(Manager); //managerMainView.Show(); view.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }