Example #1
0
        public void UpdateTag(MyStoryContext dbContext, PostInput input, Post post)
        {
            if (post.Tags != null) post.Tags.Clear();

            if (input.Tags != null)
            {
                foreach (var item in input.Tags.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var tagText = item.Trim();

                    if (!string.IsNullOrWhiteSpace(tagText))
                    {
                        var cnt = dbContext.Tags.Count(t => t.TagText == tagText);
                        if (cnt > 0)
                        {
                            var tag = dbContext.Tags.First(t => t.TagText == tagText);
                            post.Tags.Add(tag);
                        }
                        else
                        {
                            post.Tags.Add(new Tag { TagText = tagText });
                        }
                    }
                }
            }
        }
Example #2
0
 public static void CreateAccountAndBlog(MyStoryContext dbContext)
 {
     dbContext.Blogs.Add(new Blog
                     {
                         Title = BlogTitle,
                         BlogOwner = new Account
                                     {
                                         Email = AccountEmail,
                                         Password = AccountPasword,
                                         Name = AccountName
                                     }
                     });
     dbContext.SaveChanges();
 }
Example #3
0
 public void TestInitialize()
 {
     // Arrange
     _dbContext = new MyStoryContext();
     _dbContext.Database.Delete();
     _dbContext.Database.Create();
 }
Example #4
0
 //protected override void Dispose(bool disposing)
 //{
 //    DbContext.Dispose();
 //    base.Dispose(disposing);
 //}
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     base.OnActionExecuting(filterContext);
     this.DbContext = new MyStoryContext();
     SetBlogName();
 }
Example #5
0
        public static void CreateOneComment(MyStoryContext dbContext)
        {
            var comment = new Comment
            {
                Content = CommentContent,
                DateCreated = DateTime.Now,
                PostId = 1,
                CommenterId = 1,
            };

            dbContext.Comments.Add(comment);
            dbContext.SaveChanges();
        }
Example #6
0
        public static void CreateOnePost(MyStoryContext dbContext)
        {
            var blogId = dbContext.Blogs.SingleOrDefault().Id;

            dbContext.Posts.Add(new Post
            {
                Id = 1,
                BlogId = blogId,
                Content = PostContent,
                DateCreated = DateTime.Now,
                DateModified = DateTime.Now,
                Title = PostTitle,
                LocationOfWriting = new Location()
            });

            dbContext.SaveChanges();
        }
Example #7
0
        public static void CreateOneCommenter(MyStoryContext dbContext)
        {
            var commenter = new Commenter
            {
                Id = 1,
                Name = CommenterName,
                Email = CommenterEmail
            };

            dbContext.Commenters.Add(commenter);
            dbContext.SaveChanges();
        }
Example #8
0
 public MyStoryController()
 {
     DbContext = new MyStoryContext();
     Init();
 }