Esempio n. 1
0
        public Forum CreateForum(String categoryId, String forumId, String name, Int32 sortOrder, String description)
        {
            Guid id;

            if (!Guid.TryParse(categoryId, out id))
            {
                throw new ArgumentException(nameof(categoryId));
            }

            if (String.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            Dbos.Forum parentForum = null;
            if (!String.IsNullOrWhiteSpace(forumId))
            {
                Guid parentForumId;
                if (!Guid.TryParse(forumId, out parentForumId))
                {
                    throw new ArgumentException(nameof(forumId));
                }

                parentForum = this.forumRepository.FindById(parentForumId);
            }

            Dbos.Category parent = this.categoryRepository.FindById(id);
            if (parent == null)
            {
                throw new ArgumentException(nameof(categoryId));
            }

            return(this.CreateForum(parent, parentForum, name, sortOrder, description));
        }
 public static Category ToModel(this Dbos.Category category)
 {
     return(new Category {
         Id = category.Id.ToString(),
         Name = category.Name,
         Description = category.Description,
         SortOrder = category.SortOrder,
         CustomData = category.CustomData
     });
 }
Esempio n. 3
0
        public Category FindCategoryById(String categoryId)
        {
            Guid id;

            if (!Guid.TryParse(categoryId, out id))
            {
                throw new ArgumentException(nameof(categoryId));
            }
            Dbos.Category category = this.categoryRepository.FindById(id);
            return(category.ToModel());
        }
Esempio n. 4
0
        public Category CreateCategory(String name, Int32 sortOrder, String description)
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }
            Dbos.Category model = this.categoryRepository.Create(new Dbos.Category {
                Name        = name,
                SortOrder   = sortOrder,
                Description = description
            });

            return(model.ToModel());
        }
Esempio n. 5
0
        private static void PopulatedLevel0(Dbos.Category c, Category cat)
        {
            List <Forum> forums = new List <Forum>();

            c.Forums.Where(f => f.Level == 0).ToList().ForEach(f => {
                Forum forum    = f.ToModel();
                forum.Category = cat;

                PopulateLevel1(cat, f, forum);

                forums.Add(forum);
            });

            cat.Forums = forums;
        }
Esempio n. 6
0
        public Category UpdateCategory(String categoryId, String name, Int32 sortOrder, String description)
        {
            Guid id;

            if (!Guid.TryParse(categoryId, out id))
            {
                throw new ArgumentException(nameof(categoryId));
            }
            Dbos.Category category = this.categoryRepository.FindById(id);

            category.Name        = name;
            category.SortOrder   = sortOrder;
            category.Description = description;

            category = this.categoryRepository.Update(category);
            return(category.ToModel());
        }
Esempio n. 7
0
        private Forum CreateForum(Dbos.Category category, Dbos.Forum parentForum, String name, Int32 sortOrder, String description)
        {
            Dbos.Forum newForum = new Dbos.Forum {
                CategoryId  = category.Id,
                Name        = name,
                SortOrder   = sortOrder,
                Description = description,
                Level       = 0
            };
            if (parentForum != null)
            {
                newForum.ParentForumId = parentForum.Id;
                newForum.Level         = parentForum.Level + 1;
            }

            Dbos.Forum model = this.forumRepository.Create(newForum);
            return(model.ToModel());
        }
Esempio n. 8
0
        public Category FindCategoryPlus2Levels(String categoryId)
        {
            Guid id;

            if (!Guid.TryParse(categoryId, out id))
            {
                throw new ArgumentException(nameof(categoryId));
            }

            Dbos.Category category = this.categoryRepository.FindAll()
                                     .Include(c => c.Forums)
                                     .SingleOrDefault(c => c.Id == id);

            Category output = category.ToModel();

            PopulatedLevel0(category, output);

            return(output);
        }