Example #1
0
        public bool Create(ExamDTO examDTO, Guid userId)
        {
            try
            {
                Exam exam = new Exam
                {
                    Id          = Guid.NewGuid(),
                    Password    = RandomString(8),
                    OwnerId     = userId,
                    Time        = examDTO.Time,
                    Name        = examDTO.Name,
                    BankId      = examDTO.BankId,
                    StartTime   = examDTO.StartTime,
                    EndTime     = examDTO.EndTime,
                    Description = examDTO.Description
                };
                DbContext.Exams.Add(exam);

                examDTO.QuestionId.ForEach(x => DbContext.ExamQuestions.Add(new ExamQuestion
                {
                    QuestionId = x,
                    ExamId     = exam.Id,
                }));

                DbContext.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #2
0
 public long Add(ExamDTO model)
 {
     using (MyDbContext ctx = new MyDbContext())
     {
         ExamEntity ef = new ExamEntity();
         ef.Address        = model.Address;
         ef.ClassName      = model.ClassName;
         ef.ExamTime       = model.ExamTime;
         ef.MajorName      = model.MajorName;
         ef.PlaceNum       = model.PlaceNum;
         ef.SchoolName     = model.SchoolName;
         ef.SFZCode        = model.SFZCode;
         ef.StuName        = model.StuName;
         ef.SysName        = model.SysName;
         ef.ZKZCode        = model.ZKZCode;
         ef.TypeId         = model.TypeId;
         ef.LLExamAddress  = model.LLExamAddress;
         ef.LLExamTime     = model.LLExamTime;
         ef.LLExamPlaceNum = model.LLExamPlaceNum;
         ef.StuId          = model.StuId;
         ef.llzwh          = model.llzwh;
         ctx.Exams.Add(ef);
         ctx.SaveChanges();
         return(ef.Id);
     }
 }
Example #3
0
        public IHttpActionResult PutExam(int id, ExamDTO examDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != examDTO.ID)
            {
                return(BadRequest());
            }

            Exam exam = db.Exams.Find(id);

            exam.Title     = examDTO.Title;
            exam.SubjectID = examDTO.SubjectID;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ExamExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IActionResult ExamCreate(ExamDTO exam)
        {
            List <Post> postList = RSSHelper.GetAllPost(Url).ToList();

            Exam newExam = new Exam();

            newExam.Header      = postList.Where(a => a.Description == exam.Description).FirstOrDefault().Header;
            newExam.Description = exam.Description;
            examService.Insert(newExam);

            int k = 0;

            for (int i = 0; i < 4; i++)
            {
                Question newQuestion = new Question();
                newQuestion.ExamID       = newExam.ID;
                newQuestion.QuestionText = exam.Questions[i].QuestionText;
                questionService.Insert(newQuestion);

                for (int j = 0; j < 4; j++)
                {
                    Option newOption = new Option();
                    newOption.QuestionID = newQuestion.ID;
                    newOption.OptionText = exam.Options[k].OptionText;
                    newOption.IsCorrect  = (j + 65 == exam.Answers[i] ? true : false);
                    optionService.Insert(newOption);
                    k++;
                }
            }

            return(RedirectToAction("Login", "Account"));
        }
Example #5
0
 public long Edit(ExamDTO model)
 {
     using (MyDbContext ctx = new MyDbContext())
     {
         BaseService <ExamEntity> bs = new BaseService <ExamEntity>(ctx);
         var data = bs.GetById(model.Id);
         if (data == null)
         {
             throw new ArgumentException("找不到记录id为:" + model.Id);
         }
         data.Address        = model.Address;
         data.ClassName      = model.ClassName;
         data.ExamTime       = model.ExamTime;
         data.LLExamAddress  = model.LLExamAddress;
         data.LLExamPlaceNum = model.LLExamPlaceNum;
         data.LLExamTime     = model.LLExamTime;
         data.MajorName      = model.MajorName;
         data.PlaceNum       = model.PlaceNum;
         data.SchoolName     = model.SchoolName;
         data.SFZCode        = model.SFZCode;
         data.StuId          = model.StuId;
         data.StuName        = model.StuName;
         data.SysName        = model.SysName;
         data.TypeId         = model.TypeId;
         data.ZKZCode        = model.ZKZCode;
         data.llzwh          = model.llzwh;
         ctx.SaveChanges();
         return(data.Id);
     }
 }
Example #6
0
        public ExamDTO ToDTO(ExamEntity ef)
        {
            ExamDTO dto = new ExamDTO();

            dto.Address         = ef.Address;
            dto.ClassName       = ef.ClassName;
            dto.ExamTime        = ef.ExamTime;
            dto.MajorName       = ef.MajorName;
            dto.PlaceNum        = ef.PlaceNum;
            dto.SchoolName      = ef.SchoolName;
            dto.SFZCode         = ef.SFZCode;
            dto.StuName         = ef.StuName;
            dto.SysName         = ef.SysName;
            dto.TypeId          = ef.TypeId;
            dto.TypeName        = ef.ExamTypes.Name;
            dto.TypeDescription = ef.ExamTypes.Description;
            dto.ZKZCode         = ef.ZKZCode;
            dto.IsLook          = ef.IsLook;
            dto.LLExamAddress   = ef.LLExamAddress;
            dto.LLExamTime      = ef.LLExamTime;
            dto.LLExamPlaceNum  = ef.LLExamPlaceNum;
            dto.StuId           = ef.StuId;
            dto.Id    = ef.Id;
            dto.llzwh = ef.llzwh;
            return(dto);
        }
Example #7
0
        public PDFHeader(ExamDTO examDTO)
        {
            _testID          = examDTO.Id;
            _examName        = examDTO.Name;
            _fullStudentName = examDTO.StudentFullName;

            _fontsize   = 12;
            _polishFont = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1257, _fontsize, Font.NORMAL);
        }
Example #8
0
        public void TestUpdateExam()
        {
            ExamDTO item = new ExamDTO();

            // Act
            examService.UpdateExam(item);
            // Assert
            Assert.AreEqual("My name is test", subjectTest.Name);
        }
 private void AsserExamTags(ExamDTO dto, Exam exam)
 {
     foreach (var examTag in exam.ExamTags)
     {
         var tag   = examTag.Tag;
         var count = dto.Tags.Where(t => t.Tag == tag.TagId).Count();
         Assert.IsTrue(count == 1);
     }
 }
Example #10
0
 public ActionResult EditExam(ExamDTO examDTO, Guid subjectId)
 {
     if (ModelState.IsValid)
     {
         examService.UpdateExam(examDTO);
         Logger.Log.Info("User " + User.Identity.GetUserId() + "save changes test ");
     }
     return(RedirectToAction("ViewExam", new { id = subjectId }));
 }
        public ExamDTO SaveExam(ExamDTO exam)
        {
            Exam newExam = _mapper.Map <Exam>(exam);

            _dataContext.Exams.Add(newExam);
            _dataContext.SaveChanges();

            return(_mapper.Map <ExamDTO>(newExam));
        }
Example #12
0
        public void TestAddNewExam()
        {
            ExamDTO item = new ExamDTO();

            // Act
            examService.AddNewTExam(item);
            examService.AddNewTExam(item);
            // Assert
            Assert.AreEqual(2, subjects.Count());
        }
Example #13
0
        public IActionResult Post([FromBody] ExamDTO exam)
        {
            if (ModelState.IsValid)
            {
                var result = _service.SaveExam(exam);
                return(Ok(result));
            }

            return(BadRequest(ModelState));
        }
Example #14
0
 public Exam MapFrom(ExamDTO entity)
 {
     return(new Exam
     {
         Title = entity.Name,
         Date = entity.Date,
         Duration = entity.Duration,
         ExamHall = entity.ExamHall,
     });
 }
Example #15
0
        public void Add(ExamDTO exam)
        {
            if (exam == null)
            {
                throw new ValidationException("Оценка не найдена", "");
            }
            Exam addingExam = AutoMap <ExamDTO, Exam> .Map(exam);

            Database.Exams.Add(addingExam);
            Database.Commit();
        }
Example #16
0
 public ExamViewModel MapFrom(ExamDTO entity)
 {
     return(new ExamViewModel
     {
         Name = entity.Name,
         Date = entity.Date,
         Hour = entity.Date.Hour,
         Minutes = entity.Date.Minute.ToString("D2"),
         Duration = entity.Duration,
         ExamHall = entity.ExamHall,
     });
 }
Example #17
0
        public ActionResult EditExam(Guid id, Guid subjectId)
        {
            ExamDTO examDTO = examService.GetExamById(id);

            if (examDTO != null)
            {
                ViewBag.subjectId = subjectId;
                Logger.Log.Info("User " + User.Identity.GetUserId() + "edit test " + id);
                return(View(examDTO));
            }
            return(HttpNotFound());
        }
        private Button ExamDetail(ExamDTO examname)
        {
            Button b = new Button();

            b.FlatStyle = FlatStyle.Flat;
            b.Size      = new Size(141, 40);
            b.Text      = examname.examID;
            b.Click    += view_Click;
            b.Tag       = examname;

            return(b);
        }
Example #19
0
 public ActionResult AddExam(ExamDTO examDTO, Guid subjectId)
 {
     if (ModelState.IsValid)
     {
         examDTO.Id = Guid.NewGuid();
         examService.AddNewTExam(examDTO);
         examService.AddNewCOnnectionSubjectExam(examDTO.Id, subjectId);
         Logger.Log.Info("User " + User.Identity.GetUserId() + "add new exam " + examDTO.Id + " to subject " + subjectId);
         return(RedirectToAction("ViewExam", new { id = subjectId }));
     }
     return(RedirectToAction("ViewExam", new { id = subjectId }));
 }
Example #20
0
        // GET: api/Exams
        public List <ExamDTO> GetExams()
        {
            List <Exam>    exams    = db.Exams.ToList <Exam>();
            List <ExamDTO> examDTOs = new List <ExamDTO>();

            foreach (var exam in exams)
            {
                ExamDTO examDTO = new ExamDTO(exam);
                examDTO.Subject = db.Subjects.Find(exam.SubjectID).Name;
                examDTOs.Add(examDTO);
            }
            return(examDTOs);
        }
 private void AssertExam(ExamDTO dto, Exam exam)
 {
     Assert.AreEqual(dto.Id, exam.Id);
     Assert.AreEqual(dto.Title, exam.Title);
     Assert.AreEqual(dto.Description, exam.Description);
     Assert.AreEqual(dto.TimeInMinutes, exam.TimeInMinutes);
     Assert.AreEqual(dto.PassPercentage, exam.PassPercentage);
     Assert.AreEqual(dto.IsPrivate, exam.IsPrivate);
     Assert.AreEqual(dto.IsPublished, exam.IsPublished);
     Assert.AreEqual(dto.IsDeleted, exam.IsDeleted);
     Assert.AreEqual(dto.CreatedAt, exam.CreatedAt);
     Assert.AreEqual(dto.UpdatedAt, exam.UpdatedAt);
 }
Example #22
0
 public void UpdateExam(ExamDTO examDTO)
 {
     try
     {
         var     config = new MapperConfiguration(cfg => cfg.CreateMap <ExamDTO, Exam>());
         IMapper mapper = config.CreateMapper();
         Database.Exams.Update(mapper.Map <ExamDTO, Exam>(examDTO));
         Database.Exams.Save();
     }
     catch (Exception ex)
     {
         Logger.Log.Error(ex.Message);
     }
 }
Example #23
0
        public PDFDocument(ExamDTO examDTO, string path)
        {
            _document = new Document(PageSize.A4, 36, 36, 36, 36);

            _examID   = examDTO.Id;
            _filename = examDTO.StudentFullName + PDFHelpers.GetMD5(_examID.ToString()) + ".pdf";
            _filepath = path + "\\";

            _writer           = PdfWriter.GetInstance(_document, new FileStream(_filepath + _filename, FileMode.Create));
            _writer.PageEvent = PDFHelpers.CreatePageEventHelper(examDTO);
            _document.Open();

            _questions           = new LinkedList <QuestionDTO>(examDTO.QuestionsDTO);
            _examAnswerPositions = new List <AnswerPositionDTO>();
        }
Example #24
0
        public IHttpActionResult Post(ExamDTO examDTO)
        {
            Exam exam = new Exam()
            {
                CategoryID = examDTO.CategoryID,
                Date       = examDTO.Date,
                Duration   = examDTO.Duration,
                IsActive   = examDTO.IsActive,
                LessonID   = examDTO.LessonID,
                Name       = examDTO.Name
            };

            _examService.Add(exam);

            return(Ok());
        }
        public ExamDTO PutPoints(int id, ExamDTO examObject)
        {
            var exam = _dataContext.Exams.FirstOrDefault(x => x.Id == id);

            if (exam == null)
            {
                throw new Exception("Exam not found");
            }

            examObject.Id = exam.Id;
            exam          = _mapper.Map <Exam>(examObject);
            _dataContext.SaveChanges();


            return(_mapper.Map <ExamDTO>(exam));
        }
Example #26
0
        //Return test choosen by id
        public ExamDTO GetExamById(Guid id)
        {
            ExamDTO examDTO = new ExamDTO();

            try
            {
                var     config = new MapperConfiguration(cfg => cfg.CreateMap <Exam, ExamDTO>());
                IMapper mapper = config.CreateMapper();
                examDTO = mapper.Map <Exam, ExamDTO>(Database.Exams.GetById(id));
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex.Message);
            }
            return(examDTO);
        }
Example #27
0
        public IHttpActionResult PostExam(ExamDTO examDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Exam exam = new Exam();

            exam.Title     = examDTO.Title;
            exam.SubjectID = examDTO.SubjectID;

            db.Exams.Add(exam);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = exam.ID }, exam));
        }
Example #28
0
        public ActionResult Edit(ExamDTO dto)
        {
            var data = examService.Edit(dto);

            if (data > 0)
            {
                return(Json(new AjaxResult {
                    Status = "ok"
                }));
            }
            else
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "添加失败!"
                }));
            }
        }
        private ExamDTO getExamDTO(int generatedExamID)
        {
            var generatedExam         = _generatedExamService.Find(generatedExamID);
            var examCoreStudentsGroup = _examCoreStudentGroupService.GetByID(generatedExam.ExamCoreStudentGroupID);
            var examCore = _examCoreService.Find(examCoreStudentsGroup.ExamCoreID);
            var student  = _generatedExamService.GetStudentByGeneratedExamID(generatedExam?.StudentGroupStudentID);

            var     questions = _generatedExamService.GetQuestionsByGeneratedExamID(generatedExamID);
            ExamDTO examDTO   = new ExamDTO()
            {
                Id              = generatedExam.Id,
                Name            = examCore.Name,
                StudentFullName = student.SurName + " " + student.Name,
                QuestionsDTO    = Mapper.Map <List <QuestionDTO> >(questions)
            };

            return(examDTO);
        }
Example #30
0
        public void Edit(ExamDTO exam)
        {
            try
            {
                if (exam == null)
                {
                    throw new ValidationException("Экзамен не найден.", "");
                }
                var findingExam = ValidateModule.ValidateExam(exam.Id);
                findingExam = AutoMap <ExamDTO, Exam> .Map(exam, findingExam);

                Database.Exams.Edit(findingExam);
                Database.Commit();
            }
            catch (ValidationException)
            {
                throw;
            }
        }