Ejemplo n.º 1
0
        public CrudResult Save(AppExam exam, List <AppQuestion> questions, string user)
        {
            exam.UpdatedBy = user;
            exam.UpdatedOn = DateTime.Now;
            if (exam.Id == 0)
            {
                exam.ExameCode = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 22);
            }

            questions.ForEach(q => { q.UpdatedOn = DateTime.Now; q.UpdatedBy = user; });

            var mapper = _config.CreateMapper();
            var dbExam = mapper.Map <AppExam, Exam>(exam);

            var examSaveResult = exam.Id == 0 ? Add <Exam>(dbExam) : Edit <Exam>(dbExam);

            if (examSaveResult.Success)
            {
                var examItem   = (Exam)examSaveResult.Entity;
                var dbQuesions = mapper.Map <List <AppQuestion>, List <Question> >(questions);

                foreach (var qus in dbQuesions)
                {
                    if (qus.TypeId == 4)
                    {
                        qus.SubText = qus.SubText.Replace("\n", "|");
                    }
                    qus.ExamId = examItem.Id;
                    var questionAddResult = qus.Id == 0 ? Add <Question>(qus) : Edit <Question>(qus);
                    if (!questionAddResult.Success)
                    {
                        return(new CrudResult(questionAddResult.Success, questionAddResult.Message));
                    }
                }
            }

            return(new CrudResult(examSaveResult.Success, examSaveResult.Message));
        }
Ejemplo n.º 2
0
 public ExamService(IUnitOfWork unitOfWork, IMapper mapper)
 {
     this.unitOfWork = unitOfWork;
     this.mapper     = mapper;
     NewExam         = new AppExam();
 }