private ServiceExport.DTO_Element ElementConvert(PageElement srcElement, ImageDataDTO Data) { ServiceExport.DTO_Element ElOut = null; if (srcElement != null) { if (srcElement.GetType() == typeof(ElementText)) { ServiceExport.DTO_ElementText OutText = new ServiceExport.DTO_ElementText(); ElementText src = (ElementText)srcElement; if (src != null) { OutText.IsHTML = src.IsHTML; OutText.Text = src.Text; } ElOut = OutText; } if (srcElement.GetType() == typeof(ElementImage)) { ServiceExport.DTO_ElementImage OutImg = new ServiceExport.DTO_ElementImage(); ElementImage src = (ElementImage)srcElement; if (src != null) { OutImg.Height = src.Height; OutImg.Path = ImageHelper.GetImageUrl(Data, src.Path); OutImg.Width = src.Width; } ElOut = OutImg; } if (srcElement.GetType() == typeof(ElementVoid)) { ElOut = null; } if (ElOut != null) { ElOut.Id = srcElement.Id; ElOut.Alignment = srcElement.Alignment; } } return(ElOut); }
/// <summary> /// Recupera una versione specifica /// </summary> /// <param name="TempalteID">L'ID del Template</param> /// <param name="VersionID">L'ID della versione. Se more o uguale a 0 </param> /// <returns>La versione specificata di un Template</returns> /// /// <remarks> /// Al momento ho scelto di utilizzare SOLO le versioni "disponibili". /// Per le versioni in Draft o con Active = false, sarà necessario fornire l'ID Version. /// In quel caso verrà utilizzata la versione specificata, indipendentemente dal suo stato. /// </remarks> public ServiceExport.DTO_Template TemplateGet(Int64 TemplateID, Int64 VersionID, String BasePath) { TemplateVersion srcVersion = null; if (VersionID > 0) { srcVersion = Manager.Get <TemplateVersion>(VersionID); } else { Template srcTemplate = Manager.Get <Template>(TemplateID); if (srcTemplate == null) { return(null); } srcVersion = (from TemplateVersion tmpVers in srcTemplate.Versions where tmpVers.IsDraft == false && tmpVers.IsActive == true orderby tmpVers.Version descending select tmpVers).FirstOrDefault(); if (srcVersion == null) { srcVersion = (from TemplateVersion tmpVers in srcTemplate.Versions where tmpVers.IsDraft == false && tmpVers.IsActive == false orderby tmpVers.Version descending select tmpVers).FirstOrDefault(); } if (srcVersion == null) { //SE non ci sono altre versioni definitive, //prendo quella in bozza (ne è prevista una sola!) srcVersion = (from TemplateVersion tmpVers in srcTemplate.Versions where tmpVers.IsDraft == true select tmpVers).FirstOrDefault(); } } if (srcVersion == null || srcVersion.Id <= 0) { return(null); } ServiceExport.DTO_Template expTemplate = new ServiceExport.DTO_Template(); expTemplate.TemplateId = srcVersion.Template.Id; expTemplate.Name = srcVersion.Template.Name; expTemplate.VersionId = srcVersion.Id; expTemplate.Version = srcVersion.Version; expTemplate.UseSkinHeaderFooter = (srcVersion.Template.Type == TemplateType.Skin); expTemplate.IsSystem = srcVersion.Template.IsSystem; expTemplate.IsEditable = !srcVersion.Template.IsSystem && srcVersion.Template.HasDraft; // MODULES expTemplate.Modules = new List <ServiceExport.DTO_Modules>(); if (srcVersion.Template != null) { var queryService = (from s in Manager.GetIQ <ServiceContent>() where s.Deleted == BaseStatusDeleted.None select s); expTemplate.Modules = queryService.Where(s => s.Template.Id == srcVersion.Template.Id).Select(s => new ServiceExport.DTO_Modules() { Id = s.Id, ModuleName = s.ModuleName, IdModule = s.ModuleId, IsActive = s.IsActive, ModuleCode = s.ModuleCode }).ToList(); ////Template tmpl = (Template)srcVersion.Template; //////List<ServiceContent> Services = tmpl.Services.ToList(); ////if (srcVersion.Template.Services != null && tmpl.Services.Count() > 0) ////{ //foreach(ServiceContent srvc in srcVersion.Template.Services.Where(srv => srv.IsActive)) //{ // ServiceExport.DTO_Modules srv = new ServiceExport.DTO_Modules(); // srv.Id = srvc.Id; // srv.IdModule = srv.IdModule; // srv.IsActive = srv.IsActive; // srv.ModuleCode = srv.ModuleCode; // srv.ModuleName = srv.ModuleName; // expTemplate.Modules.Add(srv); //} ////} } PageElement BodyEl = (from PageElement PgEl in srcVersion.Elements.Where(el => el.Position == ElementPosition.Body && el.IsActive) orderby PgEl.SubVersion descending select PgEl).FirstOrDefault(); ServiceExport.DTO_ElementText Body = new ServiceExport.DTO_ElementText(); if (BodyEl != null && BodyEl.GetType() == typeof(ElementText)) { ElementText src = (ElementText)BodyEl; if (src != null) { Body.Alignment = src.Alignment; Body.Id = src.Id; Body.IsHTML = src.IsHTML; Body.Text = src.Text; } } else { Body = new ServiceExport.DTO_ElementText(); Body.Id = -1; Body.IsHTML = true; Body.Text = "<p></p>"; } expTemplate.Body = Body; // HEADER ImageDataDTO Data = new ImageDataDTO { BaseUrl = BasePath, TemplateId = expTemplate.TemplateId, VersionId = expTemplate.VersionId }; expTemplate.Header = new ServiceExport.DTO_HeaderFooter(); expTemplate.Header.Left = ElementConvert( (from PageElement PgEl in srcVersion.Elements.Where(el => el.Position == ElementPosition.HeaderLeft && el.IsActive && el.Deleted == BaseStatusDeleted.None) orderby PgEl.SubVersion descending select PgEl).FirstOrDefault() , Data); expTemplate.Header.Center = ElementConvert( (from PageElement PgEl in srcVersion.Elements.Where(el => el.Position == ElementPosition.HeaderCenter && el.IsActive && el.Deleted == BaseStatusDeleted.None) orderby PgEl.SubVersion descending select PgEl).FirstOrDefault() , Data); expTemplate.Header.Right = ElementConvert( (from PageElement PgEl in srcVersion.Elements.Where(el => el.Position == ElementPosition.HeaderRight && el.IsActive && el.Deleted == BaseStatusDeleted.None) orderby PgEl.SubVersion descending select PgEl).FirstOrDefault() , Data); // FOOTER expTemplate.Footer = new ServiceExport.DTO_HeaderFooter(); expTemplate.Footer.Left = ElementConvert( (from PageElement PgEl in srcVersion.Elements.Where(el => el.Position == ElementPosition.FooterLeft && el.IsActive && el.Deleted == BaseStatusDeleted.None) orderby PgEl.SubVersion descending select PgEl).FirstOrDefault() , Data); expTemplate.Footer.Center = ElementConvert( (from PageElement PgEl in srcVersion.Elements.Where(el => el.Position == ElementPosition.FooterCenter && el.IsActive && el.Deleted == BaseStatusDeleted.None) orderby PgEl.SubVersion descending select PgEl).FirstOrDefault() , Data); expTemplate.Footer.Right = ElementConvert( (from PageElement PgEl in srcVersion.Elements.Where(el => el.Position == ElementPosition.FooterRight && el.IsActive && el.Deleted == BaseStatusDeleted.None) orderby PgEl.SubVersion descending select PgEl).FirstOrDefault() , Data); // SETTING expTemplate.Settings = SettingsConvert( (from DocTemplateVers.Settings Sett in srcVersion.Settings.Where(el => el.IsActive && el.Deleted == BaseStatusDeleted.None) orderby Sett.SubVersion descending select Sett ).FirstOrDefault() ); if (expTemplate.Settings != null && !string.IsNullOrEmpty(expTemplate.Settings.BackgroundImagePath) && !expTemplate.Settings.BackgroundImagePath.StartsWith("http")) { expTemplate.Settings.BackgroundImagePath = lm.Comol.Core.DomainModel.DocTemplateVers.Business.ImageHelper.GetImageUrl(expTemplate.Settings.BackgroundImagePath, BasePath, expTemplate.TemplateId, expTemplate.VersionId); } // SIGNATURES //IList<Signature> SignTEST = srcVersion.Signatures.ToList(); expTemplate.Signatures = ( from Signature srcSigns in srcVersion.Signatures.Where(srv => srv.IsActive) select SignatureConver(srcSigns, Data)).ToList(); return(expTemplate); }