예제 #1
0
        public async Task <QuestionModel> AddQuestionAsync(AddQuestionModel model)
        {
            if (!boxRepo.GetQuery().Any(x => x.Id == model.BoxId && x.UserId == model.UserId))
            {
                throw new Exception("Item Not Found!");
            }

            var isDuplicate =
                boxRepo.FirstAsync(x => x.Id == model.BoxId).Result
                .Questions.Any(x => x.Vocabulary.ToLower() == model.Vocabulary.ToLower());

            if (isDuplicate)
            {
                throw new Exception("This Question is duplicated!");
            }

            var entity = new Question
            {
                BoxId      = model.BoxId,
                MainStage  = 1,
                Meaning    = model.Meaning,
                FailCount  = 0,
                SubStage   = 1,
                Vocabulary = model.Vocabulary
            };

            await questionRepo.AddAsync(entity);

            await unitOfWork.CommitAsync();

            return(ConvertEntityToQuestionModel(entity));
        }
 public async Task <int> AddQuestion(AddQuestionModel model)
 {
     using (var _dbContext = new DataBaseContext()) {
         object[] parameters = new object[] { model.IdArea, model.Question, model.Answer, model.Type, model.IsActive };
         return(await _dbContext.ExecuteNonQueryAsync("sp_AddQuestion", parameters));
     }
 }
예제 #3
0
        public IActionResult Add(AddQuestionModel newQuestion)
        {
            int    userId        = int.Parse(HttpContext.User.FindFirstValue("Id"));
            string imageFileName = newQuestion.Image?.FileName;

            using Stream imageStream = newQuestion.Image?.OpenReadStream();
            string image = imageFileName == null ? null : _storageService.Save(imageFileName, imageStream);
            int    id    = _questionsService.Add(userId, newQuestion.Title, newQuestion.Message, image);

            return(RedirectToAction("Details", new { id }));
        }
        //Add questions method  allows to post questions on plant by taking PlantID and Question.

        public bool AddQuestion(AddQuestionModel model)
        {
            Questions questions = new Questions
            {
                PlantID     = model.PlantID,
                Question    = model.Question,
                UserID      = _userID,
                CreatedDate = DateTimeOffset.UtcNow
            };

            ctx.Questions.Add(questions);
            return(ctx.SaveChanges() == 1);
        }
        public IHttpActionResult AddQuestion(AddQuestionModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateSocialInteractionsService();

            if (!service.AddQuestion(model))
            {
                return(InternalServerError());
            }
            return(Ok("Question Added"));
        }
        public async Task <IActionResult> AddQuestion([FromBody] AddQuestionModel model)
        {
            try
            {
                model.UserId = CurrentUserId;

                var result = await questionLib.AddQuestionAsync(model);

                return(CustomResult(result));
            }
            catch (System.Exception exp)
            {
                return(CustomError(exp));
            }
        }
예제 #7
0
 public ActionResult AddQuestion(AddQuestionModel model)
 {
     try
     {
         using (DBONLINETESTEntities db = new DBONLINETESTEntities())
         {
             var result = db.addQuestion(model.QuestionType, model.Category, model.Question, model.OptionA, model.OptionB, model.OptionC, model.OptionD, model.Answer);
             return(Json(result, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception e)
     {
     }
     return(null);
 }
예제 #8
0
        public ActionResult AddMcqQuestions(AddQuestionModel model)
        {
            ViewBag.Values = model.DynamicTextBox;


            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            QuestionGroup  qg = new QuestionGroup();
            QuestionMaster qm = new QuestionMaster();

            qg = qg.GetById(con, model.QgrupId);

            List <QuestionMaster> lst = new List <QuestionMaster>();

            lst = qm.GetByGroup(model.QgrupId, con);
            qm.GetByGroup(model.QgrupId, con);

            qm.Question      = System.Web.HttpUtility.HtmlEncode(model.Question);
            qm.QuestionGroup = model.QgrupId;
            qm.SrNo          = lst.Count + 1;
            qm.QLanguage     = qg.QLanguage;
            qm.Active        = 1;
            qm.QuestionType  = "1";
            qm.CurrectAnswer = model.CurrectAnswer;
            qm.AnswerDetails = model.AnswerDescription;
            qm.CreatedDate   = DateTime.Now;
            qm.CreatedBy     = 1;
            List <QuestionOptions> lstOp = new List <QuestionOptions>();
            int srNo = 65;

            foreach (var item in model.DynamicTextBox)
            {
                char   character = (char)srNo;
                string text      = character.ToString();

                lstOp.Add(new QuestionOptions(0, 0, text, item, 1, DateTime.Now, 1));
                srNo += 1;
            }
            qm.Options = lstOp;
            qm.Create(qm, con);

            return(Redirect("AddMcqQuestions?QgrupId=" + model.QgrupId));
        }
예제 #9
0
        public ActionResult AddMcqQuestions(int QgrupId = 1)
        {
            if (Session["uid"] == null)
            {
                return(Redirect("../Account/Login?ReturnUrl=/Practice/AddMcqQuestions?QgrupId=" + QgrupId));
            }

            ViewBag.QgrupId = QgrupId;

            AddQuestionModel model = new AddQuestionModel();
            QuestionGroup    grp   = new QuestionGroup();

            grp           = grp.GetById(con, QgrupId);
            model.QgrupId = QgrupId;
            model.Qgrup   = grp.QuestionGroupName;
            return(View(model));
        }
예제 #10
0
        public IActionResult Edit(int id, AddQuestionModel newQuestion)
        {
            int    userId        = int.Parse(HttpContext.User.FindFirstValue("Id"));
            string imageFileName = newQuestion.Image?.FileName;

            using Stream imageStream = newQuestion.Image?.OpenReadStream();
            string image = imageFileName == null ? null : _storageService.Save(imageFileName, imageStream);

            try
            {
                _questionsService.Update(userId, id, newQuestion.Title, newQuestion.Message, image);
            }
            catch (AskMateNotAuthorizedException)
            {
                return(Forbid());
            }
            return(RedirectToAction("Details", new { id }));
        }
 public IActionResult AddQuestion([FromBody] AddQuestionModel qnModel)
 {
     try
     {
         // map model to entity
         Questions qns = new Questions();
         qns.CorrectAnswer = qnModel.CorrectAnswer;
         qns.TestId        = qnModel.TestId;
         qns.Question      = qnModel.Question;
         Choicetable ops = new Choicetable();
         ops.ChoiceOne   = qnModel.ChoiceOne;
         ops.ChoiceTwo   = qnModel.ChoiceTwo;
         ops.ChoiceThree = qnModel.ChoiceThree;
         ops.ChoiceFour  = qnModel.CorrectAnswer;
         //ops.QuestionId
         _adminService.AddQuestion(qns, ops);
         return(Ok());
     }
     catch (AppException ex)
     {
         // return error message if there was an exception
         return(BadRequest(new { message = ex.Message }));
     }
 }
        public IHttpActionResult PostQuestion(AddQuestionModel model)
        {
            QuestionDTO question = new QuestionDTO();

            question.Date        = model.Date;
            question.Description = model.Description;
            question.Title       = model.Title;
            question.tags        = model.tags;
            question.username    = model.username;
            if (model.image == null && model.name == null)
            {
                question.QuestionImage = "NoImage.png";
            }
            else
            {
                question.QuestionImage = saveImage(model.image, model.name);
            }
            us.Create(question);

            ModelState.Clear();
            var use = us.Get(question.questionId);

            return(CreatedAtRoute("DefaultApi", new { id = question.questionId }, question));
        }
예제 #13
0
        public JsonResult Create(string value)
        {
            AddQuestionModel myObject = JsonConvert.DeserializeObject <AddQuestionModel>(value);

            if (myObject == null)
            {
                return(Json(new { status = "error" }));
            }
            var         temp            = "here";
            int         questionType    = myObject.selectedQType;
            AddQuestion qObj            = myObject.qObj;
            var         mcList          = myObject.mcList;
            var         selectedTagList = myObject.selectedTagList;
            //dynamic myObject = JArray.Parse(value);
            Question question;

            try
            {
                var userId = userManager.GetUserId(User);
                //a String question

                question                = new Question();
                question.UserId         = userId;
                question.QuestionValue  = qObj.qText;
                question.QuestionAnswer = qObj.qAns;
                question.QuestionType   = questionType;
                trivialGameContext.Add(question);
                trivialGameContext.SaveChanges();

                //a Multiple Choice Question
                if (questionType == 3)
                {
                    foreach (var mc in mcList)
                    {
                        QuestionMcanswer questionMcanswer = new QuestionMcanswer();
                        questionMcanswer.QuestionId = question.Id;
                        questionMcanswer.Options    = mc.value;
                        questionMcanswer.Correct    = mc.answer == true ? 1 : 0;
                        questionMcanswer.Question   = question;
                        trivialGameContext.Add(questionMcanswer);
                        trivialGameContext.SaveChanges();
                    }
                }

                //add tag relate to this question
                if (selectedTagList != null)
                {
                    foreach (var mc in selectedTagList)
                    {
                        QuestionTag questionTag = new QuestionTag();
                        questionTag.QuestionId = question.Id;
                        questionTag.TagId      = mc.value;
                        trivialGameContext.Add(questionTag);
                        trivialGameContext.SaveChanges();
                    }
                }

                return(Json(new { status = "success" }));
            }
            catch (Exception e)
            {
                return(Json(new { status = "error" }));
            }
        }
예제 #14
0
 public ActionResult <HttpResponse> AddQuestion([FromBody] AddQuestionModel addQuestionModel)
 {
     _questionsService.AddQuestion(addQuestionModel.Question, addQuestionModel.UserId, addQuestionModel.Type, addQuestionModel.AddressedTo);
     return(Ok());
 }
예제 #15
0
        public IActionResult CreateQuestion([FromBody] AddQuestionModel question)
        {
            var result = DispatchCommand(new AddNewQuestionCommand(question));

            return(result.AsActionResult(Ok));
        }
        public async Task <IHttpActionResult> saveQuestion(AddQuestionModel addQuestionModel)
        {
            var result = await services.AddQuestion(addQuestionModel);

            return(Ok(result));
        }
예제 #17
0
 public AddNewQuestionCommand(AddQuestionModel questionModel)
 {
     QuestionModel = questionModel;
 }