Exemple #1
0
        public async Task <IActionResult> Register(RegisterInputModel model)
        {
            if (ModelState.IsValid)
            {
                var response = await _accountApiClient.RegisterAsync(model);

                string result = await response.Content.ReadAsStringAsync();

                switch ((int)response.StatusCode)
                {
                case (int)HttpStatusCode.OK:
                    TempData["Message"] = "User basariyla yarildi";
                    return(RedirectToAction("Login", "Account"));

                case (int)HttpStatusCode.BadRequest:
                    var badRequest = JsonConvert.DeserializeObject <BadRequest>(result);
                    foreach (var key in badRequest.Errors.Keys)
                    {
                        foreach (var value in badRequest.Errors[key])
                        {
                            ModelState.AddModelError(key, value);
                        }
                    }
                    break;

                case (int)HttpStatusCode.Conflict:
                case (int)HttpStatusCode.InternalServerError:
                    var errors = JsonConvert.DeserializeObject <ResponseOutputModel>(result);
                    ModelState.AddModelError("Confilict", errors.Message);
                    break;
                }
            }

            return(View(model));
        }