Exemplo n.º 1
0
        public async Task <ActionResult> SaveQuestion(QuestionModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_AlertSaveFailed"));
            }
            model.QuestionTypeId = Constants.QuestionTypes.FreeText;
            if (model.QuizId == null)
            {
                await SaveUserQuestion(model);
            }
            try
            {
                bool success;
                if (!QuizService.QuestionExists(model.Id))
                {
                    success = await QuizService.AddQuestion(model.QuizId, model);
                }
                else
                {
                    success = await QuizService.EditQuestion(model.Id, model);
                }

                if (!success)
                {
                    return(PartialView("_AlertSaveFailed"));
                }
            }
            catch (Exception e)
            {
                return(PartialView("_AlertSaveFailed"));
            }
            return(PartialView("_AlertSaveSuccess"));
        }