Beispiel #1
0
        static void Main(string[] args)
        {
            using (var db = new ForumContext())
            {
                var user = new User()
                {
                    login = "******",
                    password = "******",
                    role = Role.ADMIN
                };

                var topic = new Topic()
                {
                    title = "Java"
                };
                

                var post = new Post()
                {
                    content = "Java 8 jest fajna!",
                    createdAt = DateTime.Now,
                };

                post.topic = topic;
                post.user = user;

                topic.posts.Add(post);

                user.topics.Add(topic);
                user.posts.Add(post);

                db.users.Add(user);
                db.topics.Add(topic);
                db.posts.Add(post);
                db.SaveChanges();
            }
        }
Beispiel #2
0
        public void AddPost(String content, int topID, User user)
        {
            using (var db = new ForumContext())
            {
                var post = new Post();
                post.content = content;
                post.createdAt = DateTime.Now;


                var query = from t in db.topics
                                where t.topID == topID
                                select t;

                List<Topic> results = query.ToList<Topic>();
                Topic findTopic = results[0];

                if (findTopic != null)
                {
                    findTopic.posts.Add(post);
                    post.topic = findTopic;
                }

                var findUser = db.users.Find(user.usrID);
                if (findUser != null)
                {
                    findUser.posts.Add(post);
                    post.user = findUser;
                }

                db.SaveChanges();
            }
        }
Beispiel #3
0
        public void AddPost(String content, Topic topic, User user)
        {
            using (var db = new ForumContext())
            {
                var post = new Post();
                post.content = content;
                post.createdAt = DateTime.Now;

                var findTopic = db.topics.Find(topic.topID);
                if (findTopic != null)
                {
                    findTopic.posts.Add(post);
                    post.topic = findTopic;
                }

                var findUser = db.users.Find(user.usrID);
                if (findUser != null)
                {
                    findUser.posts.Add(post);
                    post.user = findUser;
                }

                db.SaveChanges();
            }
        }