コード例 #1
0
        public Task <bool> DeleteContentItem(string path)
        {
            var existingItem = ContentItems.FirstOrDefault(p => p.Path == path);

            if (existingItem != null)
            {
                Remove(existingItem);
            }

            var steps = path.Split('/');

            if (steps.Length > 2)
            {
                var themePath = string.Join("/", steps[0], steps[1]);
                var theme     = Themes.FirstOrDefault(t => t.Id == themePath);
                if (theme != null)
                {
                    theme.ModifiedDate = DateTime.UtcNow;
                    Update(theme);
                }
            }

            UnitOfWork.Commit();

            return(Task.FromResult(true));
        }
コード例 #2
0
 /// <summary>
 /// Add a content item to the collection
 /// </summary>
 /// <param name="key"></param>
 /// <param name="type"></param>
 /// <param name="path"></param>
 public void Add <T>(string key, string path)
 {
     if (Loaded)
     {
         throw new InvalidOperationException("Cannot add content while the ContentCollection is loaded");
     }
     if (key is null)
     {
         throw new ArgumentNullException(nameof(key));
     }
     if (key.Length == 0)
     {
         throw new ArgumentException("key.Length must be > 0", nameof(key));
     }
     if (path is null)
     {
         throw new ArgumentNullException(nameof(path));
     }
     if (path.Length == 0)
     {
         throw new ArgumentException("path.Length must be > 0", nameof(path));
     }
     if (!(ContentItems.FirstOrDefault(e => e.Key == key).Key is null))
     {
         throw new ArgumentException("Content with given key already exists", nameof(key));
     }
     ContentItems.Add(new ContentItem {
         Key = key, Type = typeof(T), Path = path
     });
 }
コード例 #3
0
        public Task <bool> SaveContentItem(string path, ContentItem item)
        {
            var existingItem = ContentItems.FirstOrDefault(p => p.Path == path);

            if (existingItem != null)
            {
                existingItem.ByteContent = item.ByteContent;
                Update(existingItem);
            }
            else
            {
                item.Path = path;
                Add(item);
            }

            var steps = path.Split('/');

            if (steps.Length > 2)
            {
                var themePath = string.Join("/", steps[0], steps[1]);
                var theme     = Themes.FirstOrDefault(t => t.Id == themePath);
                if (theme != null)
                {
                    theme.ModifiedDate = DateTime.UtcNow;
                    Update(theme);
                }
                else
                {
                    theme             = new Theme();
                    theme.Id          = themePath;
                    theme.ThemePath   = themePath;
                    theme.Name        = steps[1];
                    theme.CreatedDate = DateTime.UtcNow;
                    Add(theme);
                }
            }

            UnitOfWork.Commit();

            return(Task.FromResult(true));
        }
コード例 #4
0
 public ContentItem GetContentItem(string path)
 {
     return(ContentItems.FirstOrDefault(p => p.Path == path));
 }