Ejemplo n.º 1
0
        public async Task <IActionResult> Create(NewSurveyInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            var newSurveyId = await this.surveysService.CreateSurveyAsync(inputModel);

            return(this.RedirectToAction(nameof(this.SurveyIndex)));
        }
Ejemplo n.º 2
0
        public async Task <string> CreateSurveyAsync(NewSurveyInputModel inputModel)
        {
            var newSurvey = new Survey
            {
                Title = inputModel.Title,
            };

            await this.surveysRepository.AddAsync(newSurvey);

            await this.surveysRepository.SaveChangesAsync();

            return(newSurvey.Id);
        }
Ejemplo n.º 3
0
        public async Task CreateSurveyAsync_ShouldCreateSurveyProperly()
        {
            AutoMapperConfig.RegisterMappings(typeof(SurveyViewModel).Assembly);
            var newSurveyId = "555";
            var inputModel  = new NewSurveyInputModel
            {
                Id    = newSurveyId,
                Title = "20",
            };

            var surveyId = await this.service.CreateSurveyAsync(inputModel);

            var allSurveysCount = await this.service.GetAllSurveysAsync <SurveyViewModel>();

            Assert.Equal(2, allSurveysCount.Count());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> EditSurvey(NewSurveyInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            try
            {
                await this.surveysService.EditSurveyAsync(inputModel.Id, inputModel.Title);
            }
            catch (Exception)
            {
                return(this.CustomCommonError());
            }

            return(this.RedirectToAction(nameof(this.SurveyIndex)));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> EditSurvey(string surveyId)
        {
            if (surveyId == null)
            {
                return(this.CustomNotFound());
            }

            var inputModel = new NewSurveyInputModel();

            try
            {
                var survey = await this.surveysService.GetSurveyByIdAsync <SurveyViewModel>(surveyId);

                inputModel.Title = survey.Title;
                inputModel.Id    = survey.Id;
            }
            catch (Exception)
            {
                return(this.CustomCommonError());
            }

            return(this.View(inputModel));
        }