public bool Save(DefinedContentModel model)
		{
			try
			{
				if (ValidateModel(model).Count == 0)
				{

					var item = TypeConverter.ViewModelToCore(model);
					string filePath = HttpContext.Current.Server.MapPath("~/") + Constants.CONFIG_DIRECTORY;

					//if its not empty, it means this was not created at the root
					if (model.DefinedContentParent != "-1")
					{
						var parent = DefinedContent.Cache.GetDefinedContentItem(model.DefinedContentParent);
						filePath = Path.GetDirectoryName(parent.FilePath);
					}

					filePath = filePath.TrimEnd(new[] { '\\' }) + "\\" + item.Key + "\\" + Constants.CONFIG_FILE_NAME;

					string xml = Serialiser.Serialize<DefinedContentItem>(item).OuterXml;

					System.IO.FileInfo file = new System.IO.FileInfo(filePath);
					file.Directory.Create();

					File.WriteAllText(filePath, xml);

					DefinedContent.Cache.FullRefresh();

					return true;
				}
			}
			catch (Exception) { }

			return false;
		}
示例#2
0
 public static DefinedContentItem ViewModelToCore(DefinedContentModel model)
 {
     return new DefinedContentItem()
     {
         Key = model.Key,
         Parent = model.ParentKey,
         ParentType = GetCoreResolutionType(model.ParentResolveType), //TODO: needs to get parent xpath, contentid, or key in the editor
         ResolveType = GetCoreResolutionType(model.ResolveType),
         ResolveValue = model.ResolveValue,
         ItemType = model.CreateConfig.Enabled 
             ? DefinedContentItemType.CreateAndResolve 
             : DefinedContentItemType.Resolve,
         ContentTypeAlias = model.CreateConfig.ContentTypeAlias,
         Name = model.CreateConfig.Name,
         PropertyDefaults = model.CreateConfig.PropertyMapping.Select(p => new PropertyDefault() {  PropertyAlias = p.Alias, Value = p.Value, ValueType = p.IsKey ? PropertyDefaultValueType.Key : PropertyDefaultValueType.StaticValue }).ToList()
     };
 }