Ejemplo n.º 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 });
                        }
                    }
                }
            }
        }
Ejemplo n.º 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();
 }
Ejemplo n.º 3
0
 public void TestInitialize()
 {
     // Arrange
     _dbContext = new MyStoryContext();
     _dbContext.Database.Delete();
     _dbContext.Database.Create();
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 7
0
        public static void CreateOneCommenter(MyStoryContext dbContext)
        {
            var commenter = new Commenter
            {
                Id = 1,
                Name = CommenterName,
                Email = CommenterEmail
            };

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