public HealthAssessmentTemplateEditModel GetHealthAssessmentTemplate(long templateId, long category)
        {
            HealthAssessmentTemplateEditModel model = null;

            if (templateId > 0)
            {
                var template = _healthAssessmentTemplateRepository.GetById(templateId);
                model               = Mapper.Map <HealthAssessmentTemplate, HealthAssessmentTemplateEditModel>(template);
                model.IsDefault     = false;
                model.IsPublished   = false;
                model.IsNewTemplate = false;
                model.Id            = 0;
            }
            else
            {
                model = new HealthAssessmentTemplateEditModel
                {
                    IsActive      = true,
                    IsNewTemplate = true,
                    Category      = category
                };
            }

            return(model);
        }
예제 #2
0
 public ActionResult Create(HealthAssessmentTemplateEditModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _healthAssessmentTemplateService.SaveTemplate(model, _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId);
             model.FeedbackMessage = FeedbackMessageModel.CreateSuccessMessage("Template is created successfully. You can create more templates or close this page.");
             return(View(model));
         }
         return(View(model));
     }
     catch (Exception ex)
     {
         model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("System Error:" + ex);
         return(View(model));
     }
 }
 public ActionResult QuestionTemplate(HealthAssessmentTemplateEditModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             ModelState.Clear();
             model = _healthAssessmentTemplateService.SaveTemplate(model, _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId);
             model.FeedbackMessage = FeedbackMessageModel.CreateSuccessMessage("Template is created successfully. You can create more templates or close this page.");
             return(PartialView("QuestionTemplateEditModel", model));
         }
         return(PartialView("QuestionTemplateEditModel", model));
     }
     catch (Exception ex)
     {
         _logger.Error(string.Format("System Error: exception- {0} \n stacktrace: {1} ", ex.Message, ex.StackTrace));
         model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("System Error:" + ex);
         return(PartialView("QuestionTemplateEditModel", model));
     }
 }
        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);
        }