@kickass77

Не срабатывает регистрация, проблема с условием или таблицей?

Приветствую всех! Не могу разобраться, почему выдает ошибку 500 в catch.

Функция:
public async Task<IActionResult> OnPostRegistrationService()
        {
            IActionResult ServerResponse = new JsonResult(new { status = 102 });
            try
            {
                string RequestBody = await new StreamReader(Request.Body, Encoding.UTF8).ReadToEndAsync();
                JsonElement ClientData = JsonSerializer.Deserialize<JsonElement>(RequestBody);
                CurrentDevice = HttpContext.Session.Get<UserDevice>("user_device");

                Dictionary<string, JsonElement> UserDataValid = new Dictionary<string, JsonElement>() {
                        { "Login", await Task.Run(() => Validation.UserIdValid(ClientData.GetProperty("userData").GetProperty("login").GetString())) },
                        { "FirstName", await Task.Run(() => Validation.FirstNameValid(ClientData.GetProperty("userData").GetProperty("firstName").GetString())) },
                        { "LastName", await Task.Run(() => Validation.LastNameValid(ClientData.GetProperty("userData").GetProperty("lastName").GetString())) },
                        { "Email", await Task.Run(() => Validation.EmailValid(ClientData.GetProperty("userData").GetProperty("email").GetString())) },
                        { "Password", await Task.Run(() => Validation.PasswordValid(ClientData.GetProperty("userData").GetProperty("password").GetString())) }
            };

                if (!UserDataValid.Any(x => !x.Value.GetProperty("valid").GetBoolean()))
                {
                    string HashPassword = await Task.Run(() => CryptoHelper.GetHashMD5(ClientData.GetProperty("userData").GetProperty("password").GetString()));
                    string AuthToken = await Task.Run(() => CryptoHelper.GetToken(ClientData.GetProperty("userData").GetProperty("login").GetString(), HashPassword));

                    UserDatum User = new UserDatum();
                    UserSession Session = new UserSession();

                    using (mteawebContext WebContext = new mteawebContext())
                    {

                        User.Login = ClientData.GetProperty("userData").GetProperty("login").GetString();
                        User.FirstName = ClientData.GetProperty("userData").GetProperty("firstName").GetString();
                        User.LastName = ClientData.GetProperty("userData").GetProperty("lastName").GetString();
                        User.Email = ClientData.GetProperty("userData").GetProperty("email").GetString();
                        User.Password = HashPassword;
                        User.RoleId = 2;
                        User.Img = "no-img-user.png";
                        User.Dt = DateTime.Now;
                        WebContext.UserData.Add(User);
                        await WebContext.SaveChangesAsync();

                        Session.UserId = User.Id;
                        Session.DeviceId = CurrentDevice.Id;
                        Session.Dt = DateTime.Now;
                        Session.Secure = false;
                        Session.Ip = HttpContext.Connection.RemoteIpAddress.ToString();
                        Session.DeviceName = Validation.GetDeviceByScreen(Convert.ToInt32(ClientData.GetProperty("w").GetSingle()), Convert.ToInt32(ClientData.GetProperty("h").GetSingle()));
                        WebContext.UserSessions.Add(Session);
                        await WebContext.SaveChangesAsync();

                        HttpContext.Response.Cookies.Append("usession_id", Session.Id.ToString(), Configuration.cookieOptions);

                        Directory.CreateDirectory(String.Format("wwwroot/img/users/{0}/profile", User.Id.ToString()));
                        Directory.CreateDirectory(String.Format("wwwroot/img/users/{0}/reviews", User.Id.ToString()));
                        System.IO.File.Copy("wwwroot/img/no-img-user.png", String.Format("wwwroot/img/users/{0}/profile/no-img-user.png", User.Id.ToString()), false);

                        await Authentication(ClientData.GetProperty("userData").GetProperty("login").GetString(), HttpContext);
                    }



                    ServerResponse = new JsonResult(new { status = 300, url = Url.Page("profile", new 
                        { id = ClientData.GetProperty("userData").GetProperty("login").GetString() }) });
                }
                else
                {
                    ServerResponse = new JsonResult(new { status = 409, valid = UserDataValid.Values.ToArray() });
                }
            }
            catch(Exception ex)
            {
                ServerResponse = new JsonResult(new { status = 500, msg = ex.Message });
            }

            return ServerResponse;
        }


UserData таблица:

627dff640e58c782079927.png

Session:

627dffa38e05b413372287.png
  • Вопрос задан
  • 27 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы