コード例 #1
0
        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());
                }
            }
        }