private void InsertRssBlog(BlogContext context, IList <Tag> tags) { var post1 = new Post(); post1.CreationDate = DateTime.UtcNow; post1.Title = "Post1 title of rss blog"; post1.Content = "Post1 content if rss blog"; post1.PostTags = new List <PostTag> { new PostTag { Post = post1, Tag = tags[0] } }; var rssBlog = new RssBlog(); rssBlog.Url = RSS_BLOG_URL; rssBlog.Rating = 4.123456789m; rssBlog.RssUrl = RSS_BLOG_RSS_URL; rssBlog.Posts = new List <Post> { post1 }; context.Blogs.Add(rssBlog); context.SaveChanges(); }
public async Task <IActionResult> Edit(int id, [Bind("RssUrl,BlogId,Name,Url,BlogType,Timestamp")] RssBlog rssBlog) { if (id != rssBlog.BlogId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(rssBlog); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RssBlogExists(rssBlog.BlogId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(rssBlog)); }
private static async Task TablePerTypeDemoAsync() { var dbContext = CreateDbContext(); var admin = new User() { Username = "******", Email = "*****@*****.**" }; dbContext.Users.Add(admin); // new table Blogs var blog = new Blog() { Name = "Entity Framework Core", Description = "Blog about EF", CreatedBy = admin }; // new Table RssBlogs var rssBlog = new RssBlog() { Name = "RSS Entity Framework Core", Description = "RSS Blog about EF", CreatedBy = admin, Url = "Codesanook.com" }; dbContext.Blogs.AddRange(blog, rssBlog); dbContext.SaveChanges(); // Iterate the result foreach (var blogItem in dbContext.Set <RssBlog>().Select(b => new { b.Name, b.Url })) { Console.WriteLine($"blog name: {blogItem.Name}, URL: {blogItem.Url}"); } }
public async Task <IActionResult> Create([Bind("RssUrl,BlogId,Name,Url,BlogType,Timestamp")] RssBlog rssBlog) { if (ModelState.IsValid) { _context.Add(rssBlog); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(rssBlog)); }