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 }); } } } } }
public static void CreateAccountAndBlog(MyStoryContext dbContext) { dbContext.Blogs.Add(new Blog { Title = BlogTitle, BlogOwner = new Account { Email = AccountEmail, Password = AccountPasword, Name = AccountName } }); dbContext.SaveChanges(); }
public void TestInitialize() { // Arrange _dbContext = new MyStoryContext(); _dbContext.Database.Delete(); _dbContext.Database.Create(); }
//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(); }
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(); }
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(); }
public static void CreateOneCommenter(MyStoryContext dbContext) { var commenter = new Commenter { Id = 1, Name = CommenterName, Email = CommenterEmail }; dbContext.Commenters.Add(commenter); dbContext.SaveChanges(); }
public MyStoryController() { DbContext = new MyStoryContext(); Init(); }