Example #1
0
        public PreQualificationTestTemplate Save(PreQualificationTestTemplate domainObject, IEnumerable <PreQualifiedQuestionEditModel> questions)
        {
            if (domainObject == null)
            {
                return(null);
            }
            using (var adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                using (var scope = new TransactionScope())
                {
                    var entity = Mapper.Map <PreQualificationTestTemplate, PreQualificationTestTemplateEntity>(domainObject);

                    if (!adapter.SaveEntity(entity))
                    {
                        throw new PersistenceFailureException();
                    }

                    DeletePreQualificationTemplateQuestion(entity.Id);
                    SavePreQualificationTemplateQuestion(entity.Id, questions);

                    var template = GetById(entity.Id);

                    scope.Complete();
                    return(template);
                }
            }
        }
 public PreQualifiedQuestionTemplateEditModel CreateEditModel(PreQualificationTestTemplate preQualificationTestTemplate, IEnumerable <PreQualificationQuestion> questions, IEnumerable <long> selectedQuestionIds,
                                                              IEnumerable <long> dependentTestIds)
 {
     return(new PreQualifiedQuestionTemplateEditModel()
     {
         Id = preQualificationTestTemplate.Id,
         IsActive = preQualificationTestTemplate.IsActive,
         IsPublished = preQualificationTestTemplate.IsPublished,
         Name = preQualificationTestTemplate.TemplateName,
         TestId = preQualificationTestTemplate.TestId,
         Questions = questions.Select(x => new PreQualifiedQuestionEditModel()
         {
             Id = x.Id,
             Question = x.Question,
             IsSelected = !selectedQuestionIds.IsNullOrEmpty() && selectedQuestionIds.Contains(x.Id)
         }).ToArray(),
         DependentTestIds = dependentTestIds
     });
 }
Example #3
0
        public PreQualifiedQuestionTemplateEditModel SaveTemplate(PreQualifiedQuestionTemplateEditModel model, long orgRoleUserId)
        {
            PreQualificationTestTemplate dbTemplate = null;

            var template = _preQualifiedQuestionTemplateFactory.GetPreQualifiedQuestionTemplateDomain(model);

            if (template.Id > 0)
            {
                dbTemplate           = _preQualificationTestTemplateRepository.GetById(template.Id);
                template.CreatedBy   = dbTemplate.CreatedBy;
                template.CreatedDate = dbTemplate.CreatedDate;
                template.UpdatedDate = DateTime.Now;
                template.UpdatedBy   = orgRoleUserId;
            }
            else
            {
                template.CreatedBy   = orgRoleUserId;
                template.CreatedDate = DateTime.Now;
            }

            template = _preQualificationTestTemplateRepository.Save(template, model.Questions.Where(x => x.IsSelected));
            model.Id = template.Id;

            if (!model.DependentTestIds.IsNullOrEmpty())
            {
                var dependentTests = model.DependentTestIds.Select(x => new PreQualificationTemplateDependentTest
                {
                    TemplateId = template.Id,
                    TestId     = x,
                    IsActive   = true
                });

                _preQualificationTemplateDependentTestRepository.SaveCollection(dependentTests);
            }

            return(model);
        }