Пример #1
0
        public ActionResult SetTemplateIsActiveState(long templateId, bool isActive)
        {
            var template = _healthAssessmentTemplateRepository.GetById(templateId);

            if (template.IsDefault && template.IsPublished && template.TemplateType.HasValue && template.TemplateType.Value == (long)HealthAssessmentTemplateType.Event)
            {
                return(Json(new { IsSuccess = false, Message = "Template can not be deactivated since it default template for event. To deactivate it, Please make another template as default and publish it." }, JsonRequestBehavior.AllowGet));
            }

            template.IsActive = isActive;
            _healthAssessmentTemplateRepository.Save(template);
            return(Json(new { IsSuccess = true, Message = isActive ? "Template activated successfully." : "Template deactivated successfully." }, JsonRequestBehavior.AllowGet));
        }
        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);
        }