Example #1
0
        public async Task <bool> RegistrationUser(IFCore.User user, IFCore.UserInfo userInfo)
        {
            try
            {
                using (managerdbContext context = new managerdbContext())
                {
                    context.Users.Add(new Users()
                    {
                        Email    = user.Email,
                        Password = user.Password
                    });
                    context.UsersInfo.Add(new UsersInfo()
                    {
                        UserName       = userInfo.UserName,
                        UserStatus     = userInfo.UserStatus,
                        UserDepartment = userInfo.UserDepartment,
                        UserGroup      = userInfo.UserGroup
                    });
                    await context.SaveChangesAsync();

                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
Example #2
0
        private async void ButtonReg_Click(object sender, RoutedEventArgs e)
        {
            CheckValidateForm checkValidate = new CheckValidateForm();

            switch (PersonComboBox.SelectedIndex)
            {
            case 0:
                if (!String.IsNullOrWhiteSpace(PasswordBoxPasswordOrigin.Password) && !String.IsNullOrWhiteSpace(TextBoxNameUser.Text))
                {
                    if (checkValidate.IsValidateEmail(TextBoxNameUser.Text))
                    {
                        if (checkValidate.IsValidatePassword(PasswordBoxPasswordOrigin.Password))
                        {
                            CreateLoadAnimation(MainAuthRegGrid);
                            ReferenseDALClass refClassDAL = new ReferenseDALClass();
                            //await Task.Run((Action)delegate () { this.Dispatcher.BeginInvoke((ThreadStart)delegate () { var userExcl = methodsCheckUser.CheckExclusiveUser(TextBoxLogin.Text); }); }).ConfigureAwait(true);
                            bool userExcl = refClassDAL.SetConnectionDBCheckExcluziveUser(TextBoxNameUser.Text);
                            if (userExcl)
                            {
                                try
                                {
                                    IFCore.User userLogin = new IFCore.User()
                                    {
                                        Email    = TextBoxNameUser.Text,
                                        Password = cryptPassword.CalculateMD5Hash(PasswordBoxPasswordOrigin.Password).ToString()
                                    };
                                    IFCore.UserInfo userInfo = new IFCore.UserInfo()
                                    {
                                        UserStatus     = PersonComboBox.SelectedValue.ToString(),
                                        UserDepartment = TeacherNameorDepartment.SelectedValue.ToString(),
                                        UserGroup      = GroupListComboBox.SelectedValue.ToString()
                                    };
                                    await refClassDAL.SetConnectionDBRegUser(userLogin, userInfo);

                                    loadedControl.StopAnimation();
                                    SeccessfulReg();
                                }
                                catch (Exception ex)
                                {
                                    string exs = ex.ToString();
                                    loadedControl.StopAnimation();
                                    ErrorReg("Ошибка регистрации!");
                                }
                            }
                            else
                            {
                                loadedControl.StopAnimation();
                                ErrorReg("Учащийся с таким e-mail, зарегистрирован!");
                            }
                        }
                        else
                        {
                            BorderPasswordBoxUser.Background = Brushes.Red;
                            ErrorReg("Пароль не соотвествует требования!");
                        }
                    }
                    else
                    {
                        BorderTexBoxUser.Background = Brushes.Red;
                        ErrorReg("Логин не соотвествует требования!");
                    }
                }
                else
                {
                    if (String.IsNullOrWhiteSpace(PasswordBoxPasswordOrigin.Password))
                    {
                        BorderPasswordBoxUser.Background = Brushes.Red;
                    }
                    if (String.IsNullOrWhiteSpace(TextBoxNameUser.Text))
                    {
                        BorderTexBoxUser.Background = Brushes.Red;
                    }
                }
                break;

            case 1:
                if (!String.IsNullOrWhiteSpace(PasswordBoxPasswordOrigin.Password) && !String.IsNullOrWhiteSpace(TextBoxNameUser.Text))
                {
                    if (checkValidate.IsValidateEmail(TextBoxNameUser.Text))
                    {
                        if (checkValidate.IsValidatePassword(PasswordBoxPasswordOrigin.Password))
                        {
                            CreateLoadAnimation(MainAuthRegGrid);
                            ReferenseDALClass refClassDAL = new ReferenseDALClass();
                            bool userExcl = refClassDAL.SetConnectionDBCheckExcluziveUser(TextBoxNameUser.Text);
                            if (userExcl)
                            {
                                try
                                {
                                    await refClassDAL.SetConnectionDBRegUser(
                                        new User()
                                    {
                                        Email    = TextBoxNameUser.Text,
                                        Password = cryptPassword.CalculateMD5Hash(PasswordBoxPasswordOrigin.Password).ToString()
                                    },
                                        new UserInfo()
                                    {
                                        UserName   = TeacherNameorDepartment.SelectedValue.ToString(),
                                        UserStatus = PersonComboBox.SelectedValue.ToString()
                                    });

                                    loadedControl.StopAnimation();
                                    SeccessfulReg();
                                }
                                catch
                                {
                                    loadedControl.StopAnimation();
                                    ErrorReg("Ошибка регистрации!");
                                }
                            }
                            else
                            {
                                loadedControl.StopAnimation();
                                ErrorReg("Данный преподаватель, зарегистрирован!");
                            }
                        }
                        else
                        {
                            BorderPasswordBoxUser.Background = Brushes.Red;
                            ErrorReg("Пароль не соотвествует требования!");
                        }
                    }
                    else
                    {
                        BorderTexBoxUser.Background = Brushes.Red;
                        ErrorReg("Логин не соотвествует требования!");
                    }
                }
                else
                {
                    if (String.IsNullOrWhiteSpace(PasswordBoxPasswordOrigin.Password))
                    {
                        BorderPasswordBoxUser.Background = Brushes.Red;
                    }
                    if (String.IsNullOrWhiteSpace(TextBoxNameUser.Text))
                    {
                        BorderTexBoxUser.Background = Brushes.Red;
                    }
                }
                break;
            }
        }