Beispiel #1
0
        public HealthAssessmentTemplate Save(HealthAssessmentTemplate healthAssessmentTemplate)
        {
            using (var adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                using (var scope = new TransactionScope())
                {
                    var entity = Mapper.Map <HealthAssessmentTemplate, HafTemplateEntity>(healthAssessmentTemplate);

                    if (healthAssessmentTemplate.IsDefault && healthAssessmentTemplate.IsPublished && healthAssessmentTemplate.Category == (long)HealthAssessmentTemplateCategory.HealthAssessmentTemplate)
                    {
                        UpdateDefaultStatus((HealthAssessmentTemplateType)healthAssessmentTemplate.TemplateType.Value);
                    }

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

                    DeleteHealthAssessmentTemplateQuestion(entity.HaftemplateId);
                    SaveHealthAssessmentTemplatequestion(entity.HaftemplateId, healthAssessmentTemplate.QuestionIds);
                    var template = GetById(entity.HaftemplateId);
                    scope.Complete();
                    return(template);
                }
            }
        }
        public HealthAssessmentTemplateEditModel SaveTemplate(HealthAssessmentTemplateEditModel model, long organizationRoleUserId)
        {
            HealthAssessmentTemplate templateinDb = null;

            var template = Mapper.Map <HealthAssessmentTemplateEditModel, HealthAssessmentTemplate>(model);

            if (template.Id > 0)
            {
                templateinDb = _healthAssessmentTemplateRepository.GetById(template.Id);
                template.DataRecorderMetaData = templateinDb.DataRecorderMetaData;
                template.DataRecorderMetaData.DateModified         = DateTime.Now;
                template.DataRecorderMetaData.DataRecorderModifier = new OrganizationRoleUser(organizationRoleUserId);
                if (!templateinDb.IsPublished && template.IsPublished)
                {
                    template.PublicationDate = DateTime.Now;
                }
            }
            else
            {
                template.DataRecorderMetaData = new DataRecorderMetaData(organizationRoleUserId, DateTime.Now, null);
                if (template.IsPublished)
                {
                    template.PublicationDate = DateTime.Now;
                }
            }

            using (var scope = new TransactionScope())
            {
                template = _healthAssessmentTemplateRepository.Save(template);
                scope.Complete();
            }

            model.Id = template.Id;

            return(model);
        }