Пример #1
0
        public JsonResult ExamEdit(int ExamId, ExamModel ExamModel)
        {
            try
            {
                if (ExamId == 0)
                {
                    Core3Base.Infra.Data.Entity.Exam Exam = new Core3Base.Infra.Data.Entity.Exam
                    {
                        ExamName = ExamModel.Exam.ExamName,
                        IsActive = ExamModel.Exam.IsActive,
                    };

                    return(Json(_ExamService.Add(Exam).HttpGetResponse()));
                }
                else
                {
                    var Exam = _ExamService.GetExamById(ExamId).Result;
                    Exam.ExamName     = ExamModel.Exam.ExamName;
                    Exam.IsActive     = ExamModel.Exam.IsActive;
                    Exam.DateModified = DateTime.Now;

                    return(Json(_ExamService.Update(Exam).HttpGetResponse()));
                }
            }
            catch (Exception e)
            {
                return(Json(e.Message));
            }
        }
Пример #2
0
        public IActionResult Create(CreateExamDTO Exam)
        {
            var a      = RSSHelper.GetSubjects("https://www.wired.com/feed/rss");
            int examID = _examService.Add(new Entity.Exam
            {
                Header      = a.Where(x => x.Description == Exam.Description).FirstOrDefault().Title,
                MemberID    = HttpContext.Session.GetObjectFromJson <Member>("Member").ID,
                Description = Exam.Description
            });

            foreach (var item in Exam.Question)
            {
                int quesID = _questionOfExamService.Add(
                    new QuestionOfExam
                {
                    ExamID   = examID,
                    Question = item.Question
                }
                    );
                for (int i = 0; i < 4; i++)
                {
                    _optionsOfQuestionService.Add(new OptionsOfQuestion
                    {
                        Option           = item.Options[i].Option,
                        QuestionOfExamID = quesID,
                        IsCorrect        = ((Convert.ToInt32(item.Answer) - 65) == i) ? true : false
                    });
                }
                foreach (var item2 in item.Options)
                {
                }
            }
            return(RedirectToAction("Index", "Member"));
        }
Пример #3
0
        public ActionResult Create(Exam exam)
        {
            if (_examService.Add(exam))
            {
                return(View("Index"));
            }

            return(View("Index"));
        }
        public IActionResult Create([FromBody] Exam exam)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _service.Add(exam);
            return(Ok(exam));
        }
Пример #5
0
        public async Task <IActionResult> AddExam(int lessonId, string userName)
        {
            AppUser student = await _userManager.FindByNameAsync(userName);

            Lesson           lesson    = _lessonService.GetById(lessonId);
            List <Questions> questions = _questionsSerice.GetAll().Where(x => x.LessonId == lessonId).ToList();

            if (questions.Count == 0)
            {
                return(RedirectToAction("ErrorQuestion"));
            }
            else
            {
                try
                {
                    StudentLesson entity = new StudentLesson()
                    {
                        AppUserId = student.Id,
                        AppUser   = student,
                        LessonId  = lessonId,
                        Lesson    = lesson
                    };
                    _studentLesson.Add(entity);

                    var studentId  = student.Id;
                    var totalCount = questions.Count();
                    var point      = 100 / totalCount;
                    foreach (var item in questions)
                    {
                        Exam model = new Exam()
                        {
                            StudentId = studentId,
                            Question  = item.Question,
                            Name      = lesson.LessonName,
                            Option1   = item.Option1,
                            Option2   = item.Option2,
                            Option3   = item.Option3,
                            Option4   = item.Option4,
                            Option5   = "Empty",
                            Right     = item.Reply,
                            Reply     = null,
                            Time      = totalCount,
                            Point     = point,
                            LessonId  = lessonId
                        };
                        _examService.Add(model);
                    }
                    return(Redirect("/Home/Details/" + lessonId));
                }
                catch (Exception)
                {
                    return(NotFound());
                }
            }
        }
Пример #6
0
        // [Authorize(Roles = "Exam.Add")]
        public IActionResult Add(ExamDto examDto)
        {
            var result = _examService.Add(examDto);

            if (result.Success)
            {
                return(Ok(result.Message));
            }

            return(BadRequest(result.Message));
        }
Пример #7
0
        public async Task <IActionResult> Add([FromBody] ExamAddDto model)
        {
            var result = await _examService.Add(model);

            if (result.Message != ApiResultMessages.Ok)
            {
                return(BadRequest(result));
            }


            return(Ok(result));
        }
Пример #8
0
 public IActionResult Create(Exam exam)
 {
     if (ModelState.IsValid)
     {
         _examService.Add(exam);
         bool result = _examService.Save() > 0;
         if (result)
         {
             return(RedirectToAction("Index"));
         }
     }
     return(View(exam));
 }
Пример #9
0
        public IActionResult Add([FromQuery] ExamViewModel model)
        {
            var ExamResponse = _ExamService.Add(new Exam
            {
                ExamName = model.ExamName,
                LessonId = model.LessonId
            });

            if (ExamResponse.IsSucceeded && ExamResponse.Result != null)
            {
                return(Ok(ExamResponse.Result));
            }
            return(ExamResponse.HttpGetResponse());
        }
Пример #10
0
        public ActionResult Add([FromBody] ExamDto examDto)
        {
            var request          = JsonConvert.DeserializeObject <ExamDto>(JsonConvert.SerializeObject(examDto));
            var context          = new ValidationContext(request);
            var validationResult = new List <ValidationResult>();

            bool isValid = Validator.TryValidateObject(request, context, validationResult, true);

            if (!isValid)
            {
                return(BadRequest(validationResult));
            }

            _examService.Add(examDto);
            return(StatusCode(201));
        }
Пример #11
0
        public IActionResult CreateExam(ExamCreateModel model)
        {
            Exam exam = new Exam();
            int  d    = Convert.ToInt32(model.Title);

            exam.ExamContent = model.Content;
            exam.ExamTitle   = titles[d - 1].ToString();
            exam.CreatedDate = DateTime.Now;
            _examService.Add(exam);
            int exam_id = exam.ExamId;

            for (int i = 0; i < 4; i++)
            {
                Question question = new Question();
                question.ExamId          = exam_id;
                question.QuestionContent = model.Questions[i].QuestionContent;
                _questionService.Add(question);
                question.ExamId = exam_id;
                int question_id = question.QuestionId;

                for (int j = 0; j < 4; j++)
                {
                    Option option = new Option();
                    option.selection = model.Questions[i].Options[j].selection;

                    option.QuestionId = question_id;

                    string a = model.Questions[i].Answer.ToString().ToLower();


                    if (((model.Questions[i].Answer) - 65) == j)
                    {
                        option.IsCorrect = "true";
                    }

                    else
                    {
                        option.IsCorrect = "false";
                    }

                    _optionsService.Add(option);
                }
            }

            return(View("Index"));
        }
Пример #12
0
 public IActionResult Add(ExamDto examDto)
 {
     _examService.Add(examDto);
     return(StatusCode(201));
 }