public void SaveUserExecute(string parametar1, string parametar2) { MessageBoxResult result = MessageBox.Show("Are you sure you want to registrate?", "Registration", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { User.Password = parametar1; User.GenderId = selectedGender.GenderId; User.MaritalStatusId = selectedMaritalStatus.MaritalStatusId; try { if (User.UserId == 0) { bool uniqueUserName = service.CheckUsernameUser(User.Username); bool uniqueJMBG = service.CheckJmbg(User.Jmbg); bool uniqueEmail = service.CheckUniqueEmail(Menager.Email); if (!uniqueUserName && !uniqueEmail && !uniqueJMBG) { int userId = service.AddCompanyUser(User); if (userId != 0) { if (User.RoleId == 1) { Menager.UserId = userId; Menager.NumOfSuccessfulProjects = 0; Menager.BackupPassword = parametar2 + "WPF"; if (service.AddMenagerUser(Menager) != 0) { MessageBox.Show("You have successfully registrate!"); Logging.LoggAction("RegistrationMenager", "Info", "Succesfull registrate new menager"); MainWindow mainView = new MainWindow(); mainView.Show(); registrationView.Close(); } } else if (User.RoleId == 3) { Random random = new Random(); menager = ManagerList[random.Next(0, ManagerList.Count)]; Worker.UserId = userId; Worker.SectorId = selectedSector.SectorId; Worker.PositionId = selectedPosition.PositionId; Worker.QualificationsId = selectedQualification.QualificationsId; Worker.ManagerId = menager.ManagerId; if (service.AddWorkerUser(Worker) != 0) { MessageBox.Show("You have successfully registrate!"); Logging.LoggAction("RegistrationWorker", "Info", "Succesfull registrate new worker"); MainWindow mainView = new MainWindow(); mainView.Show(); registrationView.Close(); } } } } else if (uniqueUserName) { MessageBox.Show("Username is not unique!"); } else if (uniqueJMBG) { MessageBox.Show("JMBG is not unique!"); } else if (uniqueEmail) { MessageBox.Show("Email is not unique!"); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); Logging.LoggAction("RegistrationMenager", "Error", ex.ToString()); } } }
public void SaveExecute() { try { User.GenderId = selectedGender.GenderId; User.LocationId = selectedLocation.LocationId; int sectorId = service.CheckSectorName(User.SectorName); if (sectorId == 0) { sectorId = service.AddSector(User.SectorName); } User.SectorId = sectorId; if (User.UserId == 0) { bool uniqueJmbg = service.CheckJmbg(User.Jmbg); bool uniqueIdNumber = service.CheckIDNumber(User.IDNumber); if (!uniqueIdNumber && !uniqueJmbg) { if (selectedMenager == null) { User.MenagerId = 0; } else { User.MenagerId = selectedMenager.UserId; } if (service.AddUser(User) != 0) { MessageBox.Show("You have successfully added new employee"); Thread t = new Thread(() => { Logging.LoggAction("Add new emplyee", "Success", "Succesfully added new emplyee"); }); t.IsBackground = true; t.Start(); } } else if (uniqueJmbg) { MessageBox.Show("Jmbg is not unique!"); } else if (uniqueIdNumber) { MessageBox.Show("ID number is not unique!"); } } else { bool uniqueJmbg = service.Check_JMBG_Update(User.Jmbg, User.UserId); bool uniqueIdNumber = service.Check_IDNumber_Update(User.IDNumber, User.UserId); User.MenagerId = selectedMenagerForEdit.UserId; if (uniqueIdNumber && uniqueJmbg) { service.UpdateUser(User); MessageBox.Show("You have successfully changed employee data"); Thread t = new Thread(() => { Logging.LoggAction("Update emplyee", "Success", "Succesfully updated emplyee"); }); t.IsBackground = true; t.Start(); } else if (!uniqueJmbg) { MessageBox.Show("Jmbg is not match with user!"); } else if (!uniqueIdNumber) { MessageBox.Show("ID number is not not match with user!"); } } MainWindow main = new MainWindow(); main.Show(); addEditUserView.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }