public IHttpActionResult UpdateOption(int id, [FromBody] OptionBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            OptionDTO optionToUpdate = this._optionService.GetById(id);

            if (optionToUpdate == null)
            {
                return(Content(HttpStatusCode.NotFound,
                               $"Test category with id={id} does not exist."));
            }

            OptionDTO updatedOption = new OptionDTO()
            {
                QuestionId = model.QuestionId,
                Body       = model.Body,
                Index      = model.Index,
                IsCorrect  = model.IsCorrect
            };

            this._optionService.Update(updatedOption);

            return(Ok());
        }
        public async Task <IActionResult> AddNew(OptionBindingModel model)
        {
            var serviceModel = Mapper.Map <OptionServiceModel>(model);

            await this.adminOptionsService.CreateNewAsync(serviceModel);

            return(RedirectToAction("Index"));
        }
        public IActionResult Create([FromQuery] int surveyId, [FromQuery] int questionId)
        {
            var viewModel = new OptionBindingModel()
            {
                QuestionId = questionId
            };

            ViewBag.SurveyId = surveyId;

            return(View(viewModel));
        }
        public async Task <IActionResult> Edit([FromForm] int surveyId, [FromForm] OptionBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var optionModel = model.ToServiceModel();
                await _optionService.EditOptionAsync(optionModel);

                return(RedirectToAction($"Edit", "Survey", new { surveyId }));
            }

            return(View(model));
        }
        public async Task <IActionResult> AddNew()
        {
            var optionTypeModels = await this.adminOptionTypesService.GetAll()
                                   .To <SelectListItem>()
                                   .ToArrayAsync();

            var model = new OptionBindingModel()
            {
                OptionTypes = optionTypeModels
            };

            return(View(model));
        }
        public IHttpActionResult CreateOption([FromBody] OptionBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            OptionDTO newOption = new OptionDTO()
            {
                QuestionId = model.QuestionId,
                Body       = model.Body,
                Index      = model.Index,
                IsCorrect  = model.IsCorrect
            };

            _optionService.Add(newOption);

            return(this.Ok());
        }