Пример #1
0
 public CategoryItem Add(CategoryItem item)
 {
     return new CategoryItem()
     {
         Id = Guid.NewGuid(),
         Title = "test"
     };
 }
Пример #2
0
        /// <summary>
        /// Add new item
        /// </summary>
        /// <param name="item">Post</param>
        /// <returns>Saved item with new ID</returns>
        public Data.Models.CategoryItem Add(CategoryItem item)
        {
            if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.CreateNewPosts))
                throw new System.UnauthorizedAccessException();

            var cat = (from c in Category.Categories.ToList() where c.Title == item.Title select c).FirstOrDefault();
            if (cat != null)
                throw new ApplicationException("Title must be unique");

            try
            {
                var newItem = new Category();
                UpdateCoreFromJson(newItem, item);
                return GetJsonFromCore(newItem);
            }
            catch (Exception ex)
            {
                Utils.Log(string.Format("CategoryRepository.Add: {0}", ex.Message));
                return null;
            }
        }
Пример #3
0
        static List<CategoryItem> GetCategories(ICollection<Category> categories)
        {
            if (categories == null || categories.Count == 0)
                return null;

            //var html = categories.Aggregate("", (current, cat) => current + string.Format
            //("<a href='#' onclick=\"ChangePostFilter('Category','{0}','{1}')\">{1}</a>, ", cat.Id, cat.Title));
            var categoryList = new List<CategoryItem>();
            foreach (var coreCategory in categories)
            {
                var item = new CategoryItem();
                item.Id = coreCategory.Id;
                item.Title = coreCategory.Title;
                item.Description = coreCategory.Description;
                item.Parent = ItemParent(coreCategory.Parent);
                categoryList.Add(item);
            }
            return categoryList;
        }
        /// <summary>
        /// Update item
        /// </summary>
        /// <param name="item">Item to update</param>
        /// <returns>True on success</returns>
        public bool Update(CategoryItem item)
        {
            if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.EditOwnPosts))
                throw new System.UnauthorizedAccessException();

            var cat = (from c in Category.Categories.ToList() where c.Title == item.Title && c.Id != item.Id select c).FirstOrDefault();
            if (cat != null)
                throw new ApplicationException("Title must be unique");

            var core = (from c in Category.Categories.ToList() where c.Id == item.Id select c).FirstOrDefault();

            if (core != null)
            {
                UpdateCoreFromJson(core, item);
                return true;
            }
            return false;
        }
 /// <summary>
 /// Add new item
 /// </summary>
 /// <param name="item">Post</param>
 /// <returns>Saved item with new ID</returns>
 public Data.Models.CategoryItem Add(CategoryItem item)
 {
     if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.CreateNewPosts))
         throw new System.UnauthorizedAccessException();
     try
     {
         var newItem = new Category();
         UpdateCoreFromJson(newItem, item);
         return GetJsonFromCore(newItem);
     }
     catch (Exception ex)
     {
         Utils.Log(string.Format("CategoryRepository.Add: {0}", ex.Message));
         return null;
     }
 }
Пример #6
0
 public bool Update(CategoryItem item)
 {
     return true;
 }