public IActionResult Create(SurveyCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string UserID    = _userManager.GetUserId(User);
                var    this_User = _userService.GetById(UserID);
                Survey newSurvey = new Survey()
                {
                    Creator         = this_User,
                    SurveyName      = model.SurveyName,
                    NumberQuestions = model.NumberQuestions,
                    SampleSize      = model.SampleSize,
                    Status          = model.Status.Value
                };

                if (!_surveyService.SurveyExists(newSurvey))
                {
                    _surveyService.Add(newSurvey);
                    return(RedirectToAction("index"));
                }
                else
                {
                    return(Content("Survey Already exists..."));
                }
            }
            return(Content(ModelState.Values.ToString()));
        }
Exemple #2
0
        public async Task <IActionResult> Create([FromBody] SurveyCreateViewModel model)
        {
            var    user      = User.Identity.Name;
            string userIdStr = User.FindFirstValue(CustomClaimType.UserId);
            int    userId;

            if (String.IsNullOrEmpty(userIdStr) || !int.TryParse(userIdStr, out userId))
            {
                return(Ok(new ErrorServiceRespose("User id in token is invalid")));
            }

            var createSurveyCommand = new CreateSurveyCommand
            {
                Title       = model.Title,
                Description = model.Description,
                UserEmail   = user
            };

            var result = await _commandDispatcher.ExecuteAsync(createSurveyCommand);

            if (result.IsSuccess)
            {
                return(Ok(new OkServiceResponse <string>("")));
            }

            return(Ok(new ErrorServiceRespose(result.Error)));
        }
        public IActionResult Edit(int id)
        {
            Survey this_survey          = _surveyService.GetSurveyById(id);
            SurveyCreateViewModel model = new SurveyCreateViewModel()
            {
                SurveyName      = this_survey.SurveyName,
                NumberQuestions = this_survey.NumberQuestions,
                SampleSize      = this_survey.SampleSize,
                Status          = this_survey.Status
            };

            return(View(model));
        }
        public async Task <IActionResult> Create(SurveyCreateViewModel model)
        {
            try
            {
                var userId = GetUserId();
                await service.Add(model.ToDomain(userId));

                return(Json(new { Success = true, Message = "Pesquisa adicionada com sucesso" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Success = false, ex.Message }));
            }
        }
        public IActionResult Edit(int id, SurveyCreateViewModel model)
        {
            var this_survey = _surveyService.GetSurveyById(id);

            if (ModelState.IsValid && this_survey != null)
            {
                this_survey.NumberQuestions = model.NumberQuestions;
                this_survey.SurveyName      = model.SurveyName;
                this_survey.Status          = model.Status.Value;
                this_survey.SampleSize      = model.SampleSize;
                var result = _surveyService.Commit();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Exemple #6
0
        public IActionResult Create(SurveyCreateViewModel model)
        {
            int maxQuestions = 15;
            int maxOptions   = 10;

            bool isInvalid = model == null ||
                             model.NumberOfQuestions <= 0 ||
                             model.NumberOfOptions <= 1 ||
                             model.NumberOfQuestions > maxQuestions ||
                             model.NumberOfOptions > maxOptions;

            if (isInvalid)
            {
                return(NotFound());
            }

            ViewBag.Numbers = model;
            return(View());
        }
        public IActionResult Create()
        {
            SurveyCreateViewModel model = new SurveyCreateViewModel();

            return(View(model));
        }