public ActionResult AddPost(string content, string title, string tags) { var db = new BlogDb(@"Data Source=.\sqlexpress;Initial Catalog=Blog;Integrated Security=True"); Post post = new Post { Content = content, Title = title, Date = DateTime.Now }; db.AddPost(post); db.AddTagsToPost(tags, post.Id); return RedirectToAction("Index"); }
public ActionResult AddPost(string title, string text, string tags) { var db = new BlogDb(_connectionString); var post = new Post { Date = DateTime.Now, Text = text, Title = title }; db.AddPost(post); IEnumerable<Tag> postTags = tags.Split(',').Select(t => { int tagId = db.AddTag(t); return new Tag { Id = tagId, Name = t }; }); db.AddTagsToPost(post, postTags); return RedirectToAction("Index", "Blog"); }