예제 #1
0
        public IActionResult Create(string url)
        {
            var model = new CreateExamViewModel();

            model = PreparePostDetailModel(url, model);
            return(View(model));
        }
예제 #2
0
        public IActionResult Create(string url, CreateExamViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var exam = new Exam {
                        Title = model.Title, Detail = model.Content
                    };
                    exam.Questions.Add(ModelToEntity(model.Question1));
                    exam.Questions.Add(ModelToEntity(model.Question2));
                    exam.Questions.Add(ModelToEntity(model.Question3));
                    exam.Questions.Add(ModelToEntity(model.Question4));

                    Db.Exams.Add(exam);
                    Db.SaveChangesAsync();

                    return(RedirectToAction(nameof(List)));
                }
            }
            catch (Exception ex)
            {
                ViewData["Message"] = "Bir hata oluştu!";
                //TODO:loglama
            }

            model = PreparePostDetailModel(url, model);
            return(View(model));
        }
예제 #3
0
        public async Task CreateExamAsyncShouldCreateNewExam()
        {
            var user = new ApplicationUser()
            {
                Id = Guid.NewGuid().ToString(),
            };

            var courseId = Guid.NewGuid().ToString();

            var createExamViewModel = new CreateExamViewModel
            {
                Name           = "exam",
                Description    = "This is a test exam description.",
                QuestionsCount = 5,
                QuestionsOrder = OrderType.Fixed,
                ChoicesOrder   = OrderType.Fixed,
                Creator        = user,
                CourseId       = courseId,
            };

            await this.Service.CreateExamAsync(createExamViewModel);

            var exam = await this.DbContext.Exams.FirstOrDefaultAsync();

            var examsCount = this.DbContext.Exams.ToArray().Count();

            Assert.Equal(1, examsCount);
            Assert.Equal("exam", exam.Name);
            Assert.Equal("This is a test exam description.", exam.Description);
            Assert.Equal(5, exam.QuestionsCount);
            Assert.Equal(OrderType.Fixed, exam.QuestionsOrder);
            Assert.Equal(OrderType.Fixed, exam.ChoicesOrder);
            Assert.Equal(user, exam.Creator);
            Assert.Equal(courseId, exam.CourseId);
        }
예제 #4
0
        private CreateExamViewModel PreparePostDetailModel(string url, CreateExamViewModel model)
        {
            try
            {
                using (var client = new WebClient())
                {
                    var html    = client.DownloadString(new Uri(url));
                    var htmlDoc = new HtmlDocument();
                    htmlDoc.LoadHtml(html);

                    var title = htmlDoc.DocumentNode.SelectNodes("//h1[@class='content-header__row content-header__hed']")
                                .FirstOrDefault()?.InnerText;
                    model.Title = title;

                    var pContent = htmlDoc.DocumentNode
                                   .SelectNodes("//div[@class='article__chunks']//div[@class='grid--item body body__container article__body grid-layout__content']//p");
                    model.Content = "";
                    pContent.ToList().ForEach(p =>
                    {
                        model.Content += $"{p.InnerText}\n";
                    });
                }
            }
            catch (Exception ex)
            {
                //TODO: loglama
            }

            return(model);
        }
예제 #5
0
        public ActionResult CreateExam(CreateExamViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            Exam exam = new Exam()
            {
                Id       = Guid.NewGuid().ToString(),
                Name     = model.Name,
                DateFrom = model.DateFrom,
                DateTo   = model.DateTo,
                IsActive = model.IsActive
            };

            var Level = Helpers.Context.Levels.FirstOrDefault(l => l.Name == model.LevelName);

            if (
                Helpers.Context.Exams.Any(
                    e => e.Name == model.Name &&
                    e.DateFrom == model.DateFrom &&
                    e.DateTo == model.DateTo))
            {
                ModelState.AddModelError(string.Empty, "This exam already exists.");
                return(View());
            }
            exam.Level = Level;
            Helpers.Context.Exams.Add(exam);
            Helpers.Context.SaveChanges();
            ViewBag.Message = "Exam successfully added.";
            return(View(new CreateExamViewModel()));
        }
예제 #6
0
 public void Init()
 {
     createExamViewModel = new CreateExamViewModel();
     createExamViewModel.GetCourses();
     createExamViewModel.GetClasses();
     createExamViewModel.GetQuestions();
     ExamTypeDropDown.ItemsSource = Enum.GetValues(typeof(ExamType));
 }
 public CreateExam()
 {
     this.InitializeComponent();
     CreateExamViewModel = new CreateExamViewModel();
     this.DataContext    = CreateExamViewModel;
     NotYetCreatedExamListView.ItemsSource = CreateExamViewModel.CreatedQuestions;
     SeeCreatedExamListView.ItemsSource    = CreateExamViewModel.ExamList;
 }
예제 #8
0
        public ActionResult CreateExam()
        {
            var viewModel = new CreateExamViewModel();
            var clients   = _context.Courses.
                            Select(s => new {
                Text  = s.CourseCode + " - " + s.CourseName,
                Value = s.Id
            }).ToList();

            ViewBag.CoursesList = new SelectList(clients, "Value", "Text");
            return(View(viewModel));
        }
예제 #9
0
        public async Task <IActionResult> Create()
        {
            var user = await this.userManager.GetUserAsync(this.HttpContext.User);

            var userCourses = await this.coursesService.GetMyCoursesWithoutPagesAsync <CourseViewModel>(user);

            var viewModel = new CreateExamViewModel()
            {
                UserCourses = userCourses,
            };

            return(this.View(viewModel));
        }
예제 #10
0
        public async Task <IActionResult> Create(CreateExamViewModel viewModel)
        {
            var user = await this.userManager.GetUserAsync(this.HttpContext.User);

            viewModel.Creator = user;

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

            await this.examsService.CreateExamAsync(viewModel);

            return(this.RedirectToAction("Index"));
        }
예제 #11
0
        public async Task <IActionResult> CreateExam([FromBody] CreateExamViewModel examDto)
        {
            var questionsInExam = new List <Question>();

            for (int questionNum = 0; questionNum < examDto.TotalNumberOfQuestions; questionNum++)
            {
                questionsInExam.Add(new Question(questionNum + 1, new WrongAnswer(ReasonIsWrong.NotSpecified)));
            }

            var newExam = new Exam(examDto.Name, examDto.Date, questionsInExam);
            var result  = await _examRepo.Insert(newExam);

            if (result.IsFailure)
            {
                return(BadRequest(result.Error));
            }

            return(Created("", newExam.Id));
        }
예제 #12
0
        public ActionResult CreateExam(CreateExamViewModel exam)
        {
            if (ModelState.IsValid)
            {
                var teacher = _context.Teachers.Single(t => t.UserName == User.Identity.Name);
                var newExam = new Exam();
                newExam.CourseId      = exam.CourseId;
                newExam.TeacherId     = teacher.Id;
                newExam.ExamName      = exam.ExamName;
                newExam.ExamDate      = exam.ExamDate.Date.Add(exam.ExamTime.TimeOfDay);
                newExam.IsOnline      = exam.IsOnline;
                newExam.IsCatagorized = exam.IsCatagorized;
                _context.Exams.Add(newExam);
                _context.SaveChanges();
                Session["ExamId"] = newExam.Id;
                Session["QNo"]    = 0;
                return(RedirectToAction("SetQuestion", "Teachers", new { id = newExam.Id }));
            }

            return(View());
        }
예제 #13
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var course = _courseManager.GetCourseWithActiveExamsById(id);

            course.Organization = _orgManager.GetOrganizationById(course.OrganizationId);

            var createExamVm = new CreateExamViewModel {
                Course           = course,
                OrganizationName = course.Organization.Name
            };

            var courseEditVm = Mapper.Map <CourseEditViewModel>(course);

            courseEditVm.CreateExamVm = createExamVm;

            ViewBag.Course = course;
            return(View(courseEditVm));
        }