public void AddContentType(Data.Guid siteGuid, CmsContentType type) { if (String.IsNullOrEmpty(type.Guid)) type.Guid = Data.Guid.Create().Value; if (!type.IsGlobalType) type.SubscriptionId = siteGuid.Value; //make sure this name doesn't already exist CmsContentTypeDao dao = new CmsContentTypeDao(); CmsContentType existing = dao.FindBySiteAndName(type.SubscriptionId, type.Name); if (existing != null) throw new ArgumentException("This type name already exists and may not be used again."); using (Transaction tx = new Transaction()) { dao.Save<CmsContentType>(type); tx.Commit(); } type = GetContentType(type.Guid); }
/// <summary> /// Creates a duplicate of the specified content type. Adjusting the names as necessary to avoid conflicts. /// </summary> /// <param name="guid"></param> /// <param name="systemType"></param> public void Duplicate(Data.Guid siteGuid, CmsContentType typeToCopy) { String systemName = typeToCopy.Name; //Make sure that this system name doesn't already exist CmsContentTypeDao dao = new CmsContentTypeDao(); CmsContentType existing = dao.FindBySiteAndName(siteGuid.Value, systemName); if (existing != null) systemName = systemName + "_c"; CmsContentType type = new CmsContentType(); type.Guid = System.Guid.NewGuid().ToString(); type.DisplayName = typeToCopy.DisplayName; type.Description = type.Description; type.IsEditorVisible = type.IsEditorVisible; type.IsFileType = type.IsFileType; type.IsGlobalType = false; type.Name = systemName; type.SubscriptionId = siteGuid.Value; type.TitleFieldName = typeToCopy.TitleFieldName; AddContentType(siteGuid,type); //Copy all of the fields IList<CmsContentTypeField> fieldsToCopy = GetContentTypeFields(typeToCopy.Guid); foreach (CmsContentTypeField fieldToCopy in fieldsToCopy) { CmsContentTypeField field = new CmsContentTypeField(); field._SelectOptions = fieldToCopy._SelectOptions; field.Columns = fieldToCopy.Columns; field.Description = fieldToCopy.Description; field.FieldType = fieldToCopy.FieldType; field.IsRequired = fieldToCopy.IsRequired; field.IsSystemDefault = fieldToCopy.IsSystemDefault; field.Name = fieldToCopy.Name; field.ObjectType = fieldToCopy.ObjectType; field.Parent = fieldToCopy.Parent; field.Position = fieldToCopy.Position; field.Rows = fieldToCopy.Rows; field.SystemName = fieldToCopy.SystemName; AddContentTypeField(type, field); } }
public ContentQueryBuilder SetWhereClause(String clause) { if (this.subscriptionGuid == null) throw new ApplicationException("The subscription guid must be set prior to calling this method"); if (!String.IsNullOrEmpty(clause)) { CmsContentTypeDao dao = new CmsContentTypeDao(); //Get the fields and their types for the content type CmsContentType type = dao.FindBySiteAndName(this.subscriptionGuid, this.contentType); IList<CmsContentTypeField> fields = dao.FindFieldsByContentTypeGuid(type.Guid); //Perform error checking and make sure that there's not more than one paren pair int leftParens = clause.Count(f => f == '('); int rightParens = clause.Count(f => f == ')'); if (leftParens > 1) throw new ArgumentException("The where clause '" + clause + "' is not currently supported. Only a single set of parens may be present"); if (leftParens != rightParens) throw new ArgumentException("The where clause '" + clause + "' is not valid. Parentheses mitmatch. Expected " + leftParens + " but found " + rightParens); //Make sure there are not any conditional statements if (ConditionalMatch.IsMatch(clause)) throw new ArgumentException("The where clause '" + clause + "' is not valid: GooeyCms does not currently support conditional where clauses"); //Parse the actual string clause = clause.Replace("'", ""); clause = clause.Replace("(", ""); clause = clause.Replace(")", ""); Match match = StatementMatch.Match(clause); if (!match.Success) throw new ArgumentException("The where clause '" + clause + "' is not in a valid format. Format should be: field-name [<,>,=] value. Greater-than and Less-than are only supported on datetime field types."); String fieldname = match.Groups["fieldname"].Value; String condition = match.Groups["condition"].Value; String value = match.Groups["value"].Value; //Make sure that this fieldname is valid for the content type CmsContentTypeField field = null; try { field = fields.Single(f => f.SystemName.Equals(fieldname)); } catch (InvalidOperationException e) { StringBuilder builder = new StringBuilder(); foreach (CmsContentTypeField temp in fields) { builder.Append(temp.SystemName + "|"); } throw new ArgumentException("The where clause '" + clause + "' is not valid: The content type '" + type.Name + "' does not contain the field '" + fieldname + "'. Available fields:" + builder.ToString()); } WhereInfo whereInfo = new WhereInfo(); whereInfo.Value1 = value; whereInfo.Field = field; whereInfo.ParseConditional(condition); this.whereClauses.Add(whereInfo); } return this; }