public void MapViewModelToEntity(PublishModel aModel)
        {
            DB.Template lTemplate = _tdb.Templates.Single(t => t.Id == aModel.TemplateId);

            this.UpdateTemplateSamples(aModel, lTemplate);
            this.UpdateTemplateConstraints(aModel, lTemplate);
        }
        public PublishModel MapEntityToViewModel(DB.Template aTemplate)
        {
            PublishModel lModel = new PublishModel();

            lModel.TemplateId   = aTemplate.Id;
            lModel.TemplateName = aTemplate.Name;
            lModel.TemplateOid  = aTemplate.Oid;

            foreach (DB.TemplateSample lSample in aTemplate.TemplateSamples)
            {
                XmlSample lViewSample = new XmlSample()
                {
                    Id         = lSample.Id,
                    Name       = lSample.Name,
                    SampleText = lSample.XmlSample,
                    TemplateId = aTemplate.Id
                };

                lModel.XmlSamples.Add(lViewSample);
            }

            IGSettingsManager igManager    = new IGSettingsManager(_tdb, aTemplate.OwningImplementationGuideId);
            IIGTypePlugin     igTypePlugin = aTemplate.OwningImplementationGuide.ImplementationGuideType.GetPlugin();
            string            baseLink     = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path) + "?Id=";

            int constraintCount = 0;

            foreach (DB.TemplateConstraint cDbConstraint in aTemplate.ChildConstraints.Where(y => y.Parent == null).OrderBy(y => y.Order))
            {
                PublishConstraint lConstraintView = this.BuildConstraint(_tdb, baseLink, igManager, igTypePlugin, cDbConstraint, constraintCount);
                lModel.Constraints.Add(lConstraintView);
            }

            return(lModel);
        }
 private void UpdateTemplateConstraints(PublishModel aModel, DB.Template aTemplate)
 {
     foreach (PublishConstraint lConstraintView in aModel.Constraints)
     {
         DB.TemplateConstraint lConstraint = _tdb.TemplateConstraints.Single(tc => tc.Id == lConstraintView.Id && tc.TemplateId == aTemplate.Id);
         this.UpdateConstraint(lConstraint, lConstraintView);
     }
 }
Beispiel #4
0
        public GreenTemplateSaveResult SaveGreenTemplate(GreenTemplateViewModel aUpdatedModel)
        {
            GreenTemplateSaveResult lSaveResult = new GreenTemplateSaveResult();

            DB.Template lUnderlyingTemplate = tdb.Templates.Single(t => t.Id == aUpdatedModel.TemplateId);

            ValidationRunner <GreenTemplateViewModel> lRunner
                = new ValidationRunner <GreenTemplateViewModel>(
                      new AllShallConstraintsIncludedRule(lUnderlyingTemplate),
                      new LeafLevelGreenConstraintsHaveDataType());

            ValidationResult lResult = lRunner.RunValidation(aUpdatedModel);

            if (!lResult.Pass)
            {
                StringBuilder lMessageBuilder = new StringBuilder();

                foreach (RuleValidationResult lRuleResult in lResult.Results)
                {
                    if (lRuleResult.Pass)
                    {
                        continue;
                    }

                    lMessageBuilder.AppendLine(string.Format("Error: {0}", lRuleResult.Message));
                }

                lSaveResult.ViewModel         = aUpdatedModel;
                lSaveResult.FailedValidation  = true;
                lSaveResult.ValidationMessage = lMessageBuilder.ToString();

                return(lSaveResult);
            }

            lSaveResult.FailedValidation = false;
            TemplateConstraintMapper lMapper = new TemplateConstraintMapper(tdb);

            lMapper.MapViewModelToEntity(aUpdatedModel);

            tdb.SaveChanges();

            DB.Template            lUpdatedTemplate = tdb.Templates.Single(t => t.Id == aUpdatedModel.TemplateId);
            GreenTemplateViewModel lRefreshedModel  = lMapper.MapEntityToViewModel(lUpdatedTemplate);

            lSaveResult.ViewModel = lRefreshedModel;

            return(lSaveResult);
        }
Beispiel #5
0
        public GreenTemplateViewModel GetGreenTemplate(int?templateId = null)
        {
            DB.Template lTemplate = tdb.Templates.DefaultIfEmpty(null).SingleOrDefault(t => t.Id == templateId);

            if (lTemplate == null)
            {
                return(new GreenTemplateViewModel());
            }
            else
            {
                TemplateConstraintMapper lMapper = new TemplateConstraintMapper(tdb);
                GreenTemplateViewModel   lModel  = lMapper.MapEntityToViewModel(lTemplate);

                return(lModel);
            }
        }
Beispiel #6
0
        public GreenTemplateViewModel MapEntityToViewModel(DB.Template aTemplate)
        {
            DB.GreenTemplate       lGreenTemplate = aTemplate.GreenTemplates.DefaultIfEmpty(null).FirstOrDefault();
            GreenTemplateViewModel lViewModel     = new GreenTemplateViewModel();

            if (lGreenTemplate == null)
            {
                lViewModel.Name  = this.GetCamelCaseTemplateName(aTemplate.Name);
                lViewModel.IsNew = true;
            }
            else
            {
                lViewModel.Id   = lGreenTemplate.Id;
                lViewModel.Name = lGreenTemplate.Name;
            }

            lViewModel.TemplateId   = aTemplate.Id;
            lViewModel.TemplateName = aTemplate.Name;
            lViewModel.TemplateOid  = aTemplate.Oid;

            IGSettingsManager igManager    = new IGSettingsManager(_tdb, aTemplate.OwningImplementationGuideId);
            IIGTypePlugin     igTypePlugin = aTemplate.OwningImplementationGuide.ImplementationGuideType.GetPlugin();
            string            baseLink     = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path) + "?Id=";

            int constraintCount = 0;

            foreach (DB.TemplateConstraint cDbConstraint
                     in aTemplate.ChildConstraints
                     .Where(y => y.Parent == null)
                     .Where(c => c.IsPrimitive == false)
                     .Where(c => string.IsNullOrEmpty(c.Value)).OrderBy(y => y.Order))
            {
                ConstraintViewModel lConstraintView = this.BuildConstraint(_tdb, baseLink, igManager, igTypePlugin, cDbConstraint, constraintCount);
                this.CreateIfRequiredGreenTemplateTree(lConstraintView);

                lViewModel.childConstraints.Add(lConstraintView);
            }

            return(lViewModel);
        }
        private void UpdateTemplateSamples(PublishModel aModel, DB.Template aTemplate)
        {
            IEnumerable <XmlSample> lDeletedSamples = from x in aModel.XmlSamples
                                                      where x.IsDeleted &&
                                                      x.Id.HasValue
                                                      select x;

            foreach (XmlSample lDeletedSample in lDeletedSamples)
            {
                DB.TemplateSample lSample = aTemplate.TemplateSamples.Single(s => s.Id == lDeletedSample.Id);
                _tdb.TemplateSamples.Remove(lSample);
            }

            IEnumerable <XmlSample> lNewSamples = from x in aModel.XmlSamples
                                                  where !x.Id.HasValue
                                                  select x;

            foreach (XmlSample lNewSample in lNewSamples)
            {
                DB.TemplateSample lSample = new DB.TemplateSample()
                {
                    Name = lNewSample.Name, XmlSample = lNewSample.SampleText
                };
                aTemplate.TemplateSamples.Add(lSample);
            }

            IEnumerable <XmlSample> lUpdatedSamples = from x in aModel.XmlSamples
                                                      where !x.IsDeleted &&
                                                      x.Id.HasValue
                                                      select x;

            foreach (XmlSample lUpdatedSample in lUpdatedSamples)
            {
                DB.TemplateSample lSample = _tdb.TemplateSamples.Single(ts => ts.Id == lUpdatedSample.Id);
                lSample.Name      = lUpdatedSample.Name;
                lSample.XmlSample = lUpdatedSample.SampleText;
            }
        }
Beispiel #8
0
        public string GenerateSample(DB.IObjectRepository tdb, DB.Template template)
        {
            DefaultSampleGenerator sampleGenerator = DefaultSampleGenerator.CreateDefaultSampleGenerator(tdb, template);

            return(sampleGenerator.GenerateSample());
        }
        public TemplateMetaDataModel GetMetaData(int templateId)
        {
            if (!CheckPoint.Instance.GrantEditTemplate(templateId))
            {
                throw new AuthorizationException("You do not have permission to edit this template");
            }

            DB.Template lTemplate = tdb.Templates.Single(t => t.Id == templateId);

            SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current.Application, lTemplate.ImplementationGuideType);

            schema = schema.GetSchemaFromContext(lTemplate.PrimaryContextType);

            var plugin    = lTemplate.OwningImplementationGuide.ImplementationGuideType.GetPlugin();
            var validator = plugin.GetValidator(this.tdb);

            TemplateMetaDataModel lViewModel = new TemplateMetaDataModel()
            {
                Bookmark           = lTemplate.Bookmark,
                PrimaryContext     = lTemplate.PrimaryContext,
                PrimaryContextType = lTemplate.PrimaryContextType,
                Description        = lTemplate.Description,
                Notes = lTemplate.Notes,
                Id    = lTemplate.Id,
                OwningImplementationGuideId = lTemplate.OwningImplementationGuideId,
                ImpliedTemplateId           = lTemplate.ImpliedTemplateId,
                IsOpen                   = lTemplate.IsOpen,
                Name                     = lTemplate.Name,
                Oid                      = lTemplate.Oid,
                StatusId                 = lTemplate.StatusId,
                TemplateTypeId           = lTemplate.TemplateTypeId,
                AuthorId                 = lTemplate.AuthorId,
                Author                   = string.Format("{0} {1}", lTemplate.Author.FirstName, lTemplate.Author.LastName),
                OrganizationName         = lTemplate.OrganizationName,
                MoveUrl                  = lTemplate.GetMoveUrl(),
                TemplateTypeAbbreviation = lTemplate.TemplateType.GetAbbreviation(),
                Locked                   = lTemplate.OwningImplementationGuide.IsPublished()
            };

            // Parse the validation results for the template
            lViewModel.ValidationResults = (from vr in validator.ValidateTemplate(lTemplate, schema)
                                            select new
            {
                ConstraintNumber = vr.ConstraintNumber,
                Level = vr.Level.ToString(),
                Message = vr.Message
            });

            lViewModel.Extensions = (from te in lTemplate.Extensions
                                     select new TemplateMetaDataModel.TemplateExtension()
            {
                Identifier = te.Identifier,
                Type = te.Type,
                Value = te.Value
            });

            if (lTemplate.PreviousVersion != null)
            {
                lViewModel.PreviousVersionLink = "/TemplateManagement/View/" + lTemplate.PreviousVersion.Oid;
                lViewModel.PreviousVersionName = lTemplate.PreviousVersion.Name;
                lViewModel.PreviousVersionOid  = lTemplate.PreviousVersion.Oid;
            }

            // Contained By Templates
            List <TemplateMetaDataModel.TemplateReference> containedByTemplates = new List <TemplateMetaDataModel.TemplateReference>();

            lViewModel.ContainedByTemplates = containedByTemplates;

            var containingConstraints = (from tcr in this.tdb.TemplateConstraintReferences
                                         join tc in this.tdb.TemplateConstraints on tcr.TemplateConstraintId equals tc.Id
                                         where tcr.ReferenceIdentifier == lTemplate.Oid && tcr.ReferenceType == ConstraintReferenceTypes.Template
                                         select tc);

            foreach (var containingConstraint in containingConstraints)
            {
                TemplateMetaDataModel.TemplateReference newReference = new TemplateMetaDataModel.TemplateReference()
                {
                    EditUrl             = containingConstraint.Template.GetEditUrl(),
                    ViewUrl             = containingConstraint.Template.GetViewUrl(),
                    Name                = containingConstraint.Template.Name,
                    ImplementationGuide = containingConstraint.Template.OwningImplementationGuide.GetDisplayName()
                };

                containedByTemplates.Add(newReference);
            }

            // Implied By Templates
            List <TemplateMetaDataModel.TemplateReference> impliedByTemplates = new List <TemplateMetaDataModel.TemplateReference>();

            lViewModel.ImpliedByTemplates = impliedByTemplates;

            foreach (Template implyingTemplate in this.tdb.Templates.Where(y => y.ImpliedTemplateId == templateId))
            {
                TemplateMetaDataModel.TemplateReference newReference = new TemplateMetaDataModel.TemplateReference()
                {
                    EditUrl             = implyingTemplate.GetEditUrl(),
                    ViewUrl             = implyingTemplate.GetViewUrl(),
                    Name                = implyingTemplate.Name,
                    ImplementationGuide = implyingTemplate.OwningImplementationGuide.GetDisplayName()
                };

                impliedByTemplates.Add(newReference);
            }

            return(lViewModel);
        }
 public AllShallConstraintsIncludedRule(DB.Template aUnderlyingTemplate)
 {
     _underlyingTemplate = aUnderlyingTemplate;
 }