Beispiel #1
0
        public async Task <IActionResult> CreatePost([Bind("Id", "Title", "Questions")] SurveyViewModel model)
        {
            if (!ModelState.IsValid)
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage));

                return(RedirectToAction("Create"));
            }

            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }

            var isSuccessful = await _surveyService.CreateSurveyAsync(model, currentUser);

            if (!isSuccessful)
            {
                return(RedirectToAction("Create"));
            }

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([FromForm] SurveyBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var    surveyModel = model.ToServiceModel();
                string email       = User.Identity.Name;

                await _surveyService.CreateSurveyAsync(surveyModel, email);

                return(RedirectToAction($"Create", "Question", new { surveyId = surveyModel.Id }));
            }

            return(View(model));
        }