private static void SetReservationStatus(IContentBase apartment, string valueName) { var dts = new DataTypeService(); var statusEditor = dts.GetAllDataTypeDefinitions().First(x => x.Name == "Status Rezerwacji"); var preValueId = dts.GetPreValuesCollectionByDataTypeId(statusEditor.Id).PreValuesAsDictionary.Where(d => d.Value.Value == valueName).Select(f => f.Value.Id).First(); apartment.SetValue("status", preValueId); }
public void Run() { Initialise("TypeSet3"); var dataTypes = DataTypeService.GetAllDataTypeDefinitions(); var expectedDataTypes = GetDataTypes(); AssertDataTypes(dataTypes, expectedDataTypes); var docTypes = ContentTypeService.GetAllContentTypes(); var expectedDocTypes = GetDocTypes(); AssertContentTypes(docTypes, expectedDocTypes); var mediaTypes = ContentTypeService.GetAllMediaTypes(); var expectedMediaTypes = GetMediaTypes(); AssertContentTypes(mediaTypes, expectedMediaTypes); }
public ActionResult submit(BookingInfo lunch) { //Check to see if the submission is valid if (!ModelState.IsValid) { return(CurrentUmbracoPage()); } //get the datatype for the Lunch Choices so we can work with it IDataTypeDefinition datatype = Services.DataTypeService.GetDataTypeDefinitionByName("Lunch Choices"); DataTypeService dts = (DataTypeService)Services.DataTypeService; //Get the parent ID of content you want to attach the submission to var categoryContentType = Services.ContentTypeService.GetContentType("Lunchformpage"); var parent = Services.ContentService.GetContentOfContentType(categoryContentType.Id).FirstOrDefault(x => x.Name == "Lunch Chooser"); //Create a new content item under a given parent var contentService = Services.ContentService; var LunchContent = contentService.CreateContent( lunch.FirstName + " " + lunch.LastName + DateTime.Now, //Name of the new Lunch Submission content parent.Id, //Content Parent ID, where these submissions will live under "Lunchchoicedata", // the alias of the Document Type we are adding 0); //the user adding the record, 0 is the admin //Get the preValue of selected lunch choice //The dropdown on our form only contained the text and not the true value (prevalue), //we need to find the prevalue id and enter the prevalue id into Umbraco var statusEditor = dts.GetAllDataTypeDefinitions().First(x => x.Name == "Lunch Choices"); int preValueId = dts.GetPreValuesCollectionByDataTypeId(statusEditor.Id).PreValuesAsDictionary.Where(d => d.Value.Value == lunch.LunchChoice).Select(f => f.Value.Id).First(); //Set the values of each property so that we can add the new item to Umbraco LunchContent.SetValue("firstName", lunch.FirstName); LunchContent.SetValue("lastName", lunch.LastName); LunchContent.SetValue("lunchChoice", preValueId); // publish and save the new content contentService.SaveAndPublishWithStatus(LunchContent); //Return to the same page return(CurrentUmbracoPage()); }
public void Process(IEnumerable <DocumentTypeMetadata> types) { var contentTypes = new List <IContentType>(); var dataTypeDefinitions = DataTypeService.GetAllDataTypeDefinitions().ToArray(); foreach (var type in types) { var ct = ContentTypeService.GetContentType(type.Alias) ?? new ContentType(-1); ct.Name = type.Name; ct.Alias = type.Alias; ct.AllowedAsRoot = type.AllowAsRoot; ct.Description = type.Description; ct.Icon = type.Icon; ct.Thumbnail = type.Thumbnail; var properties = ct.PropertyTypes.ToArray(); var newProperties = type.Properties.Where(p => !properties.Any(x => x.Alias == p.Alias)); foreach (var property in newProperties) { var p = new PropertyType(dataTypeDefinitions.First(dtd => dtd.Name == property.DataType)) { Name = property.Name, Alias = property.Alias, Description = property.Description }; if (property.Tab == null) { ct.AddPropertyType(p); } else { ct.AddPropertyType(p, property.Tab.ToString()); } } var modifiedProperties = type.Properties.Join(properties, p => p.Alias, p => p.Alias, (meta, p) => new { Metadata = meta, PropertyType = p }); foreach (var property in modifiedProperties) { var p = property.PropertyType; var meta = property.Metadata; p.Name = meta.Name; p.DataTypeDefinitionId = dataTypeDefinitions.First(dtd => dtd.Name == meta.DataType).Id; p.Description = meta.Description; //the following hack is brought to you be the letter F var fn = p.GetType().GetProperty("PropertyGroupId", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(p) as System.Lazy <int>; if (fn != null) { var tabId = fn.Value; var tab = ct.PropertyGroups.FirstOrDefault(t => t.Id == tabId); var newTabName = meta.Tab.ToString(); var newTab = ct.PropertyGroups.FirstOrDefault(t => t.Name == newTabName); if (tab != null && tab.Name != newTabName) { if (newTab == null) { ct.AddPropertyGroup(newTabName); } ct.MovePropertyType(p.Alias, newTabName); } } } contentTypes.Add(ct); } ContentTypeService.Save(contentTypes); var preprocessedData = contentTypes .Join(types, x => x.Alias, x => x.Alias, (ct, m) => new { ct, m }) .ToDictionary(x => x.ct, x => x.m); SetupAllowedChildren(preprocessedData); SetupTemplates(preprocessedData); ContentTypeService.Save(contentTypes); }