Example #1
0
        public async Task <IActionResult> Registration(CreateUserCommand command)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.ShowMessage = true;
                ViewBag.Message     = "Something went wrong";
                return(View());
            }

            if (string.IsNullOrEmpty(command.Answer) || command.Answer.ToLowerInvariant() != "martha")
            {
                ViewBag.ShowMessage = true;
                ViewBag.Message     = "Answer isn't correct. Try again!";
                return(View());
            }

            try
            {
                CreateUserValidator.CommandValidation(command);

                await _userService.RegisterUserAsync(command);

                TempData["Registered"] = true;
                return(RedirectToAction("Index", "Home"));
            }
            catch (InternalSystemException ex)
            {
                ViewBag.ShowMessage = true;
                ViewBag.Message     = ex.Message;
                return(View());
            }
            catch (Exception)
            {
                ViewBag.ShowMessage = true;
                ViewBag.Message     = "Something went wrong";
                return(View());
            }
        }