Пример #1
0
        public async Task <string> UpdateAsync(QuestionEditViewModel model)
        {
            var question = this.GetWithAnswer(model.Id);

            if (question == null)
            {
                return(null);
            }

            question.Content = model.Content;

            var i = 0;

            foreach (var answer in question.Answers)
            {
                answer.Content = model.Answers[i].Content;
                answer.IsRight = model.Answers[i].IsRight;

                i++;
            }

            this.questionRepository.Update(question);
            await this.questionRepository.SaveChangesAsync();

            return(question.ContestId);
        }
Пример #2
0
 public ActionResult Create(QuestionEditViewModel viewModel)
 {
     if (viewModel.Upsert())
     {
         return(RedirectToAction("Index"));
     }
     return(View(viewModel));
 }
Пример #3
0
        // GET: Question/Delete/5
        public ActionResult Delete(int id)
        {
            var viewModel = new QuestionEditViewModel(id, false);

            return(ViewOr404(viewModel, () =>
            {
                viewModel.Delete();
                return RedirectToAction("Index");
            }));
        }
        public async Task <IActionResult> Create(QuestionEditViewModel evm)
        {
            IdentityUser user = await userManager.GetUserAsync(HttpContext.User);

            Question question = new Question(evm.Title, evm.Description, user.UserName);

            questionRepo.CreateQuestion(question);
            questionRepo.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Пример #5
0
 public ActionResult Edit(int id, QuestionEditViewModel viewModel)
 {
     return(ViewOr404(viewModel, () =>
     {
         if (viewModel.Upsert(true))
         {
             return RedirectToAction("Index");
         }
         return View(viewModel);
     }));
 }
Пример #6
0
        public async Task <ActionResult> Edit(QuestionEditViewModel model, FormCollection formCollection)
        {
            if (model.File != null && model.File.ContentLength > 0) // Replace image
            {
                if (model.ImageUrl != null)
                {
                    await _questionAdminService.DeleteAttachmentAsync(model.Id);

                    model.ImageUrl = null;
                }
                var extension = AttachmentsUtil.GetExtentionFromMimeType(model.File.ContentType);
                var content   = GetAttachmentContent(model.File);
                model.ImageUrl = await _questionAdminService.UploadAttachmentAsync(new UploadQuestionAttachmentRequest(model.Id, content, extension));
            }
            else if (model.DeleteImage && model.ImageUrl != null) // Delete image
            {
                await _questionAdminService.DeleteAttachmentAsync(model.Id);

                model.ImageUrl = null;
            }

            List <UpdateAnswerRequest> answers = new List <UpdateAnswerRequest>();

            for (int i = 6; i < formCollection.Count; i += 3)
            {
                UpdateAnswerRequest updateAnswerRequest = new UpdateAnswerRequest()
                {
                    Id = Guid.Parse(formCollection[i]),
                    IsCorrectAnswer = Convert.ToBoolean(formCollection[i + 1]),
                    Title           = formCollection[i + 2]
                };
                answers.Add(updateAnswerRequest);
            }

            EditQuestionRequest editQuestionRequest = new EditQuestionRequest()
            {
                Id          = model.Id,
                Title       = model.Title,
                ImageUrl    = model.ImageUrl,
                Explanation = model.Explanation,
                Answers     = answers
            };

            await _questionAdminService.EditQuestionAsync(editQuestionRequest);

            Guid themeId = await _questionAdminService.GetThemeIdByQuestionIdAsync(model.Id);

            return(RedirectToAction("Index", new { themeId }));
        }
Пример #7
0
        public ActionResult GetAnswerDivEdit(bool isInput, QuestionEditViewModel editFormValue)
        {
            object model         = new Object();
            string inputViewPath = "";
            string anserViewPath = "";

            var data = editFormValue;

            if (data.Answers?.Count == 1)
            {
                var qId = data.Answers[0].QuestionID;
                using (var db = new SATEntities())
                {
                    var otherAnsw = db.SATAnswers.Where(a => a.QuestionID == qId).ToList();
                    if (otherAnsw?.Count == 1)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            otherAnsw.Add(new SATAnswer {
                                AnswerContent = String.Empty, AnswerType = 0, IsRightAnswer = false, Mark = null, Status = false, QuestionID = qId
                            });
                        }
                    }
                    data.Answers = otherAnsw;
                }
            }
            model         = data;
            inputViewPath = "_InputAnswerDivEdit.cshtml";
            anserViewPath = "_AnswerDivEdit.cshtml";



            if (isInput)
            {
                Session["IsInputAnswer"] = true;

                return(Json(new { data = Content(Utils.Instance.RenderViewToString(@"~\Areas\ttn_content\Views\Question\" + inputViewPath, model)) }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                Session["IsInputAnswer"] = false;
                return(Json(new { data = Content(Utils.Instance.RenderViewToString(@"~\Areas\ttn_content\Views\Question\" + anserViewPath, model)) }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #8
0
        public ActionResult Edit(QuestionEditViewModel questionVM)
        {
            if (!ModelState.IsValid)
            {
                return(View("Views/QuestionEditView", questionVM));
            }
            Question question = qService.GetQuestion(questionVM.Id);

            if (question.Content == questionVM.Content && question.Title == questionVM.Title)
            {
                return(RedirectToAction("Detail", new { id = question.Id }));
            }
            if (question.UserId == _currentUserId || User.IsInRole("Administrator") || User.IsInRole("Moderator") || User.IsInRole("Expert"))
            {
                EditedLog editedlog = new EditedLog();
                editedlog.Content     = questionVM.Content;
                editedlog.CreatedDate = DateTime.Now;
                editedlog.PostId      = question.Id;
                editedlog.UserId      = User.Identity.GetUserId <int>();
                editedlog.Title       = questionVM.Title;

                question.Title   = questionVM.Title;
                question.Content = questionVM.Content;
                question.Privacy = questionVM.Privacy == 0 ? question.Privacy : questionVM.Privacy;

                question.LastEditedDate = editedlog.CreatedDate;
                question.EditedContents.Add(editedlog);

                qService.EditQuestion(question);
                return(RedirectToAction("Detail", new { id = question.Id }));
            }
            //ViewBag.ErrorMessage = "Bạn không có quyền chỉnh sửa câu hỏi này";
            //string returnUrl = Request.Cookies.Get("returnUrl") != null ? Request.Cookies.Get("returnUrl").Value : default(string);
            if (_previousUrl == default(string))
            {
                return(RedirectToAction("Detail", new { id = question.Id }));
            }
            else
            {
                return(Redirect(Url.Content(_previousUrl)));
            }
        }
        public async Task <IActionResult> Edit(QuestionEditViewModel model)
        {
            var creatorId = this.questionsService.GetCreatorId(model.Id);
            var user      = await this.userManager.GetUserAsync(this.User);

            var isAdmin = await this.userManager.IsInRoleAsync(user, GlobalConstants.AdministratorRoleName);

            if (!isAdmin && creatorId != user.Id)
            {
                return(this.RedirectToAction("Forbid", "Errors"));
            }

            var contestId = await this.questionsService.UpdateAsync(model);

            if (contestId == null)
            {
                return(this.RedirectToAction("NotFound", "Errors"));
            }

            return(this.RedirectToAction(nameof(ContestsController.Details), "Contests", new { id = contestId }));
        }
Пример #10
0
        public async Task <ActionResult> Edit(Guid id)
        {
            var question = await _questionAdminService.GetQuestionByIdAsync(id);

            EditQuestionRequest editQuestionRequest = question.ToEditQuestionRequest();

            editQuestionRequest.Answers.Shuffle();
            QuestionEditViewModel questionEditViewModel = new QuestionEditViewModel()
            {
                Id              = editQuestionRequest.Id,
                Title           = editQuestionRequest.Title,
                ImageUrl        = editQuestionRequest.ImageUrl,
                ThemeId         = editQuestionRequest.ThemeId,
                DeleteImage     = false,
                Explanation     = editQuestionRequest.Explanation,
                Answers         = editQuestionRequest.Answers,
                MaxCountAnswers = _maxCountAnswers
            };

            ViewBag.Title = $"Edit question \"{question.Title}\"";
            return(View(questionEditViewModel));
        }
Пример #11
0
        public ActionResult Edit(int id)
        {
            Question question = qService.GetQuestion(id);

            if (question.UserId == _currentUserId || User.IsInRole("Administrator") || User.IsInRole("Moderator") || User.IsInRole("Expert"))
            {
                QuestionEditViewModel questionEditVM = new QuestionEditViewModel();

                questionEditVM    = Mapper.Map <Question, QuestionEditViewModel>(question);
                ViewBag.System    = Constant.String.QuestionSystem;
                ViewBag.ReturnUrl = _previousUrl == default(string) ? Url.Action("Detail", new { id = id }) : Url.Content(_previousUrl);
                return(View("Views/QuestionEditView", questionEditVM));
            }
            //string returnUrl = Request.Cookies.Get("returnUrl") != null ? Request.Cookies.Get("returnUrl").Value : default(string);
            if (_previousUrl == default(string))
            {
                return(RedirectToAction("Detail", new { id = id }));
            }
            else
            {
                return(Redirect(Url.Content(_previousUrl)));
            }
        }
Пример #12
0
        public ActionResult Edit(QuestionAddViewModel model)
        {
            QuestionBankDbContext Db = new QuestionBankDbContext();
            Question soru            = Db.Question.SingleOrDefault(x => x.ID.Equals(model.QuestionID));

            soru.TopicID        = model.TopicID;
            soru.QuestionTypeID = model.QuestionTypeID;
            soru.Question1      = model.Question;
            soru.Point          = model.SoruPuan;
            soru.Time           = model.SoruSure;

            List <Answers> Silinecekler = Db.Answers.Where(x => x.QuestionID.Equals(model.QuestionID)).ToList();

            Db.Answers.RemoveRange(Silinecekler);
            List <Answers> lst = new List <Answers>();

            foreach (var item in model.Answers)
            {
                Answers answers = new Answers
                {
                    QuestionID = model.QuestionID,
                    Answer     = item.AnswerContent,
                    IsItTrue   = item.Val
                };
                lst.Add(answers);
            }
            Db.Answers.AddRange(lst);



            Db.SaveChanges();
            var modelview = new QuestionEditViewModel(soru.ID);

            ViewBag.Message = $"<div class='alert alert-success'><strong> Soru Başarıyla güncellendi...</strong> </div>";
            return(View(modelview));
        }
Пример #13
0
        public ActionResult Edit(int id, QuestionEditViewModel model, List <SATAnswer> Answers)
        {
            try
            {
                using (var db = new SATEntities())
                {
                    var questionEntity = db.SATQuestions.Find(id);
                    ViewBag.EditQuestion = true;
                    var hasInput = true;
                    var textType = new SelectListItem()
                    {
                        Value = "1", Text = "Nhập vào"
                    };
                    var choiceType = new SelectListItem()
                    {
                        Value = "0", Text = "Chọn câu", Disabled = hasInput ? true : false
                    };
                    ViewBag.AnswerType = new SelectList(new List <SelectListItem>()
                    {
                        choiceType, textType
                    }, "Value", "Text", hasInput ? "1" : "0");
                    var examContentID = questionEntity.ExamContentID != null ? questionEntity.ExamContentID.Value : 0;
                    ViewBag.SelectedID = examContentID;
                    var listExamContent = new ExamContentSelectList().GetExamContentSelectList(examContentID);
                    ViewBag.ExamContentID = listExamContent;
                    var listType = new SelectList(db.SATTypes.ToList(), "TypeID", "TypeName", questionEntity.TypeID);
                    ViewBag.Type = listType;

                    List <SelectListItem> listCalc = UseCalcSelectList();
                    ViewBag.UseCalc = new SelectList(listCalc, "Value", "Text");
                    if (!ModelState.IsValid)
                    {
                        if (Session["IsInputAnswer"] != null)
                        {
                            ViewBag.IsInputAnswer = (bool)Session["IsInputAnswer"];
                        }
                        ViewBag.FormValue = JsonConvert.SerializeObject(model);
                        return(View("EditWithAnswer", model));
                    }


                    questionEntity.ExamContentID   = model.ExamContentID;
                    questionEntity.HasInputAnswer  = model.HasInputAnswer;
                    questionEntity.QuestionContent = model.QuestionContent;
                    questionEntity.QuestionNo      = model.QuestionNo;
                    questionEntity.Status          = model.Status;
                    questionEntity.Title           = model.Title;
                    questionEntity.TypeID          = model.TypeID;



                    var entry = db.Entry <SATQuestion>(questionEntity);

                    entry.State = System.Data.Entity.EntityState.Modified;

                    if (Answers.Count == 1)
                    {
                        var qID   = Answers[0].QuestionID;
                        var _answ = Answers[0];
                        var other = db.SATAnswers.Where(a => a.QuestionID == qID && a.ID != _answ.ID).ToList();
                        foreach (var item in other)
                        {
                            item.Status = false;
                            var _entry = db.Entry <SATAnswer>(item);
                            _entry.State = System.Data.Entity.EntityState.Modified;
                        }
                    }
                    foreach (var item in Answers)
                    {
                        var _entity = db.SATAnswers.Find(item.ID);
                        _entity.AnswerContent = item.AnswerContent;
                        _entity.AnswerType    = item.AnswerType;
                        _entity.IsRightAnswer = item.IsRightAnswer;
                        _entity.Mark          = item.Mark;
                        _entity.QuestionID    = id;
                        _entity.Status        = item.Status;
                        _entity.Explanation   = item.Explanation;

                        var _entry = db.Entry <SATAnswer>(_entity);
                        _entry.State = System.Data.Entity.EntityState.Modified;
                    }
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                if (Session["IsInputAnswer"] != null)
                {
                    ViewBag.IsInputAnswer = (bool)Session["IsInputAnswer"];
                }
                ViewBag.FormValue = JsonConvert.SerializeObject(model);
                return(View("EditWithAnswer", model));
            }
        }
Пример #14
0
        // GET: Question/Edit/5
        public ActionResult Edit(int id)
        {
            var model = new QuestionEditViewModel(id);

            return(ViewOr404(model, () => View(model)));
        }
Пример #15
0
        public ActionResult Edit(int ID)
        {
            var model = new QuestionEditViewModel(ID);

            return(View(model));
        }