예제 #1
0
        public ActionResult Create(Thread thread)
        {
            if (ModelState.IsValid)
            {
                db.Threads.Add(thread);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(thread));
        }
예제 #2
0
        public T Create(T entity)
        {
            var newItem = DbSet.Add(entity);

            if (!_shareContext)//If the context is shared, it is up to its owner (i.e. the Unit Of Work) to save the changes
            {
                context.SaveChanges();
            }

            return(entity);
        }
예제 #3
0
        public ActionResult Create(Post post, int threadid = 0)
        {
            if (ModelState.IsValid)
            {
                post.ThreadID = threadid;
                db.Posts.Add(post);
                db.SaveChanges();
                return(RedirectToAction("Index", new { threadidd = threadid }));
            }

            return(View(post));
        }
예제 #4
0
        public ActionResult Create(Thread thread)
        {
            if (thread.ThreadTitle == null)
            {
                thread.ThreadTitle = "Empty";
            }
            if (ModelState.IsValid)
            {
                thread.TUserID = this.User.Identity.Name;
                db.Threads.Add(thread);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(thread));
        }
예제 #5
0
        public ActionResult Create(Post post, int threadid = 0)
        {
            if (post.PostTitle == null)
            {
                post.PostTitle = "Empty";
            }
            if (post.PostText == null)
            {
                post.PostText = "Empty";
            }
            if (ModelState.IsValid)
            {
                post.PUserID  = this.User.Identity.Name;
                post.ThreadID = threadid;
                db.Posts.Add(post);
                db.SaveChanges();
                return(RedirectToAction("Index", new { threadidd = threadid }));
            }

            return(View(post));
        }
예제 #6
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();
        }