Exemple #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));
        }
Exemple #2
0
        public Forum FindForumPlus2Levels(String forumId)
        {
            Guid id;

            if (!Guid.TryParse(forumId, out id))
            {
                throw new ArgumentException(nameof(forumId));
            }
            IEnumerable <Dbos.Forum> forums = this.forumRepository.FindAll()
                                              .Include(f => f.Category)
                                              .Where(f => f.CategoryId == f.CategoryId)
                                              .ToList();

            Dbos.Forum forum = forums.SingleOrDefault(f => f.Id == id);
            if (forum == null)
            {
                // TODO:
                throw new ApplicationException();
            }

            Category cat    = forum.Category.ToModel();
            Forum    output = forum.ToModel();

            output.Category = cat;
            Forum dest = output;

            Dbos.Forum parentForum = forum.ParentForum;
            while (parentForum != null)
            {
                dest.ParentForum          = parentForum.ToModel();
                dest.ParentForum.Category = cat;

                dest        = dest.ParentForum;
                parentForum = parentForum.ParentForum;
            }

            output.Category = forum.Category.ToModel();
            List <Forum> subForums = new List <Forum>();

            forum.SubForums.ToList().ForEach(f => {
                Forum subForum       = f.ToModel();
                subForum.ParentForum = output;
                subForum.Category    = cat;

                List <Forum> children = new List <Forum>();
                f.SubForums.ToList().ForEach(fc => {
                    Forum child       = fc.ToModel();
                    child.ParentForum = subForum;
                    child.Category    = cat;

                    children.Add(child);
                });

                subForum.SubForums = children;
                subForums.Add(subForum);
            });
            output.SubForums = subForums;

            return(output);
        }
Exemple #3
0
        public Forum FindForumById(String forumId)
        {
            Guid id;

            if (!Guid.TryParse(forumId, out id))
            {
                throw new ArgumentException(nameof(forumId));
            }
            Dbos.Forum forum = this.forumRepository.FindById(id);
            return(forum.ToModel());
        }
 public static Forum ToModel(this Dbos.Forum forum)
 {
     return(new Forum {
         Id = forum.Id.ToString(),
         CategoryId = forum.CategoryId.ToString(),
         CustomData = forum.CustomData,
         Description = forum.Description,
         Name = forum.Name,
         SortOrder = forum.SortOrder,
         ParentForumId = forum.ParentForumId.ToString()
     });
 }
Exemple #5
0
        private static void PopulateLevel1(Category cat, Dbos.Forum f, Forum forum)
        {
            List <Forum> subForums = new List <Forum>();

            f.SubForums.Where(fc => fc.Level == 1 && fc.ParentForumId == f.Id).ToList().ForEach(fc => {
                Forum child       = fc.ToModel();
                child.Category    = cat;
                child.ParentForum = forum;
                subForums.Add(child);
            });

            forum.SubForums = subForums;
        }
Exemple #6
0
        public Topic CreateTopic(String userId, String forumId, String subject, String text, TopicType type)
        {
            Guid id;

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

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

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

            Dbos.Forum parent = this.forumRepository.FindById(id);
            if (parent == null)
            {
                throw new ArgumentException(nameof(forumId));
            }

            Dbos.Topic newTopic = new Dbos.Topic {
                ForumId = parent.Id,
                State   = TopicState.None,
                Type    = type
            };
            newTopic.Message = new Dbos.Message {
                Created  = DateTime.UtcNow,
                State    = Dbos.MessageState.None,
                Subject  = subject,
                Text     = text,
                Updated  = DateTime.UtcNow,
                AuthorId = uId,
                EditorId = uId,
            };

            newTopic = this.topicRepository.Create(newTopic);

            return(newTopic.ToModel());
        }
Exemple #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());
        }
Exemple #8
0
        public Forum UpdateForum(String forumId, String name, Int32 sortOrder, String description)
        {
            Guid id;

            if (!Guid.TryParse(forumId, out id))
            {
                throw new ArgumentException(nameof(forumId));
            }
            if (String.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }
            Dbos.Forum forum = this.forumRepository.FindById(id);

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

            forum = this.forumRepository.Update(forum);
            return(forum.ToModel());
        }