internal static EntityObject GetById <T>(int id) where T : EntityObject { if (typeof(T) == typeof(Article)) { return(ArticleRepository.GetById(id)); } if (typeof(T) == typeof(Site)) { return(SiteRepository.GetById(id)); } if (typeof(T) == typeof(Content)) { return(ContentRepository.GetById(id)); } if (typeof(T) == typeof(Field)) { return(FieldRepository.GetById(id)); } throw new Exception("Unsupported entity object type"); }
internal static int CreateDefaultFormat(int contentId, string backendUrl, string currentCustomerCode) { string objectName; using (var scope = new QPConnectionScope()) { objectName = Common.GetNewTemplateObjectName(scope.DbConnection, contentId); } var siteId = ContentRepository.GetById(contentId).SiteId; var pageTemplateId = Converter.ToInt32(QPContext.EFContext.PageTemplateSet.SingleOrDefault(t => t.SiteId == siteId && t.IsSystem).Id); var isDotNet = SiteRepository.GetById(siteId).IsDotNet; var obj = ObjectRepository.SaveObjectProperties(new BllObject { PageTemplateId = pageTemplateId, Name = objectName, Description = "Automatically Generated Object", TypeId = 2, AllowStageEdit = true, Global = false, LastModifiedBy = QPContext.CurrentUserId, Container = new Container { ContentId = contentId, OrderStatic = "c.modified desc", SelectTotal = "1", ScheduleDependence = true, RotateContent = 0, ApplySecurity = false, ShowArchived = false, CursorType = "adOpenForwardOnly", CursorLocation = "adUseClient", LockType = "adLockReadOnly" } }); obj.NetName = $"default_{obj.Id}"; ObjectRepository.UpdateObjectProperties(obj); string formatBody; var codeBehind = string.Empty; if (isDotNet) { using (var scope = new QPConnectionScope()) { formatBody = Common.FormatBodyNet(contentId, scope.DbConnection); } codeBehind = Common.CodeBehind(currentCustomerCode, backendUrl); } else { using (var scope = new QPConnectionScope()) { formatBody = Common.FormatBodyVbScript(contentId, currentCustomerCode, backendUrl, scope.DbConnection); } } var objectFormatId = FormatRepository.SaveObjectFormatProperties(new ObjectFormat { ObjectId = obj.Id, Name = "default", LastModifiedBy = QPContext.CurrentUserId, FormatBody = formatBody, NetLanguageId = isDotNet ? (int?)1 : null, NetFormatName = isDotNet ? "default" : null, CodeBehind = isDotNet ? codeBehind : null }).Id; ObjectRepository.UpdateDefaultFormatId(obj.Id, objectFormatId); using (var scope = new QPConnectionScope()) { Common.CreateContainerStatusBind(scope.DbConnection, obj.Id, contentId); } return(objectFormatId); }