Exemple #1
0
        static void Main(string[] args)
        {
            var context = new ForumDBContext();

            ResetDatabase(context);
            // var categories = context.Categories.Include(c => c.Posts).ThenInclude(p => p.Author).Include(c=>c.Posts).ThenInclude(p=>p.Replies).ThenInclude(r=>r.Author).ToArray();

            var categories = context.Categories.Select(c => new
                                                       { Name = c.Name, Posts = c.Posts.Select(p => new
                                                                                               { Title = p.Title, Content = p.Content, AuthorUsername = p.Author.Username, Replies = p.Replies.Select(r => new
                                                                                                                                                                                                      { Content = r.Content, Author = r.Author.Username }).ToArray() }).ToArray() }).ToArray();

            foreach (var category in categories)
            {
                Console.WriteLine($"{category.Name} ({category.Posts.Count()})");

                foreach (var post in category.Posts)
                {
                    Console.WriteLine($"--{post.Title}: {post.Content}");
                    Console.WriteLine($"--by {post.AuthorUsername}");

                    foreach (var reply in post.Replies)
                    {
                        Console.WriteLine($"----{reply.Content} from {reply.Author}");
                    }
                }
            }
        }
Exemple #2
0
        private static void ResetDatabase(ForumDBContext context)
        {
            context.Database.EnsureCreated();
            context.Database.Migrate();

            Seed(context);
        }
Exemple #3
0
 public Repository(ForumDBContext c)
 {
     context = c;
     //If the Repository is passed a context, then it is being shared by a unit of work, so don't
     //do individual saves within the repository. Let the context's owner (i.e. the Unit of Work)
     //do the saving
     _shareContext = true;
 }
Exemple #4
0
 public UserRepository(ForumDBContext context) : base(context)
 {
 }
Exemple #5
0
 public EFTopicsRepository(ForumDBContext context)
 {
     this.forumdbContext = context;
 }
Exemple #6
0
 public PostRepository(ForumDBContext context) : base(context)
 {
 }
 public EFMessagesRepository(ForumDBContext context)
 {
     this.forumDBContext = context;
 }
Exemple #8
0
 public EFUsersRepository(ForumDBContext context)
 {
     this.forumDBContext = context;
 }
 public EFDiscussionsRepository(ForumDBContext context)
 {
     this.forumdbContext = context;
 }
Exemple #10
0
        private static void Seed(ForumDBContext context)
        {
            var users = new[]
            {
                new User("Pesho", "123"),
                new User("Gosho", "123"),
                new User("Ivan", "123"),
                new User("Merry", "123")
            };

            var categories = new[]
            {
                new Category("C#"),
                new Category("Support"),
                new Category("Python")
            };

            var posts = new[]
            {
                new Post("C# Rulz", "true story", categories[0], users[0]),
                new Post("Python Rulz", "mhm", categories[1], users[1]),
                new Post("BBHMM", "sup", categories[2], users[3]),
            };

            var replies = new[]
            {
                new Reply("Turn it on", posts[2], users[0]),
                new Reply("Yep", posts[0], users[3])
            };
            var tags = new[]
            {
                new Tag("C#"),
                new Tag("Programming"),
                new Tag("Python"),
                new Tag("Microsoft"),
            };

            var postTags = new[]
            {
                new PostTag()
                {
                    PostId = 1, Tag = tags[0]
                },
                new PostTag()
                {
                    PostId = 1, Tag = tags[1]
                },
                new PostTag()
                {
                    PostId = 1, Tag = tags[2]
                },
                new PostTag()
                {
                    PostId = 1, Tag = tags[3]
                },
            };

            context.Users.AddRange(users);
            context.Categories.AddRange(categories);
            context.Posts.AddRange(posts);
            context.Replies.AddRange(replies);
            context.Tags.AddRange(tags);
            context.PostTags.AddRange(postTags);
            context.SaveChanges();
        }
Exemple #11
0
 public ThreadRepository(ForumDBContext context) : base(context)
 {
 }
Exemple #12
0
 public Repository()
 {
     context = new ForumDBContext();
 }
Exemple #13
0
 public RepositoryOfMessages(ForumDBContext context)
 {
     _context = context;
 }
Exemple #14
0
 public RepositoryOfTopics(ForumDBContext context)
 {
     _context = context;
 }