Пример #1
0
        private void RegisterAction(object obj)
        {
            if (!(obj is StackPanel passwordsStackPanel))
            {
                return;
            }

            foreach (var i in passwordsStackPanel.Children)
            {
                if (!(i is StackPanel childStackPanel))
                {
                    continue;
                }
                foreach (var j in childStackPanel.Children)
                {
                    if (!(j is PasswordBox passwordBox))
                    {
                        continue;
                    }
                    if (passwordBox.Name == "PasswordTextInput")
                    {
                        RegisterForm.Password = Calculator.CalculateMd5(passwordBox.Password);
                    }
                    else
                    {
                        RegisterForm.ConfirmPassword = Calculator.CalculateMd5(passwordBox.Password);
                    }
                }
            }
            if (RegisterForm.Validate())
            {
                var client = new RegistrationService.RegistrationClient("NetTcpBinding_IRegistration");
                if (client.Register(RegisterForm.Email, RegisterForm.Nickname, RegisterForm.Password))
                {
                    _frame.ShowLoginPage();
                }
                else
                {
                    MessageBox.Show("Register server error");
                }
                client.Close();
            }
        }
Пример #2
0
        public async Task <IActionResult> Index([FromBody] RegisterForm registerForm)
        {
            ResultViewModel resultViewModel = new ResultViewModel()
            {
                IsSuccess = true
            };

            if (registerForm != null)
            {
                List <string> errors = new List <string>();
                if (!registerForm.Validate(ref errors))
                {
                    resultViewModel.ErrorMessage = string.Join("\r\n", errors);
                    resultViewModel.IsSuccess    = false;
                }
                if (resultViewModel.IsSuccess)
                {
                    PhoneNumberUtil phoneUtil   = PhoneNumberUtil.getInstance();
                    PhoneNumber     NumberProto = phoneUtil.parse(registerForm.PhoneNumber, registerForm.Country.ToUpper());
                    registerForm.PhoneNumber = $"+{NumberProto.getCountryCode()}{NumberProto.getNationalNumber()}";
                    if (registerForm.Id == 0)
                    {
                        registerForm.Guid = Guid.NewGuid();
                        db.RegisterForms.Add(registerForm);
                    }
                    else
                    {
                        db.RegisterForms.Attach(registerForm);
                        db.Entry(registerForm).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    }

                    try
                    {
                        await db.SaveChangesAsync();
                    }
                    catch (Exception ex)
                    {
                        if (ex.InnerException != null)
                        {
                            if (ex.InnerException.Message.Contains("'IX_RegisterForm'"))
                            {
                                resultViewModel.IsSuccess    = false;
                                resultViewModel.ErrorMessage = "Duplicate Email not permitted";
                            }
                            if (ex.InnerException.Message.Contains("'IX_RegisterForm_1'"))
                            {
                                resultViewModel.IsSuccess    = false;
                                resultViewModel.ErrorMessage = "Duplicate FirstName,LastName and DatOfBirth not permitted";
                            }
                        }
                    }
                }
            }
            else
            {
                resultViewModel.IsSuccess    = false;
                resultViewModel.ErrorMessage = "Data is not presented";
            }

            if (resultViewModel.IsSuccess)
            {
                return(Ok());
            }

            return(BadRequest(resultViewModel.ErrorMessage));
        }