public async Task <BookChapter> RemoveAsync(Guid id) { BookChapter chapter = await _booksContext.Chapters.SingleOrDefaultAsync(c => c.Id == id); if (chapter == null) { return(null); } _booksContext.Chapters.Remove(chapter); await _booksContext.SaveChangesAsync(); return(chapter); }
private void EnsureDatabaseCreated() { if (!s_created) { using (var context = _container.GetService<BooksContext>()) { if (context.Database.EnsureCreated()) { var c1 = new BookChapter { Number = 1, Title = "Application Architectures", Pages = 35 }; var c2 = new BookChapter { Number = 2, Title = "Core C#", Pages = 42 }; var c3 = new BookChapter { Number = 3, Title = "Objects and Types", Pages = 30 }; var c4 = new BookChapter { Number = 4, Title = "Inheritance", Pages = 18 }; var c5 = new BookChapter { Number = 5, Title = "Managed and Unmanaged Resources", Pages = 20 }; var c6 = new BookChapter { Number = 6, Title = "Generics", Pages = 22 }; var c7 = new BookChapter { Number = 38, Title = "Windows Store Apps", Pages = 45 }; var c8 = new BookChapter { Number = 41, Title = "ASP.NET Web Forms", Pages = 48 }; context.Chapters.AddRange(c1, c2, c3, c4, c5, c6, c7, c8); context.SaveChanges(); } } s_created = true; } }
public void Update(BookChapter chapter) { _chapters[chapter.Id] = chapter; }
public void Add(BookChapter chapter) { chapter.Id = Guid.NewGuid().ToString(); _chapters[chapter.Id] = chapter; }
public Task UpdateAsync(BookChapter chapter) { _chapters[chapter.Id] = chapter; return Task.FromResult<object>(null); }
public Task AddAsync(BookChapter chapter) { chapter.Id = Guid.NewGuid(); _chapters[chapter.Id] = chapter; return Task.FromResult<object>(null); }
public async Task UpdateAsync(BookChapter chapter) { _booksContext.Chapters.Update(chapter); await _booksContext.SaveChangesAsync(); }
public async Task AddAsync(BookChapter chapter) { _booksContext.Chapters.Add(chapter); await _booksContext.SaveChangesAsync(); }
public Task UpdateAsync(BookChapter chapter) { _chapters[chapter.Id] = chapter; return(Task.FromResult <object>(null)); }
public Task AddAsync(BookChapter chapter) { chapter.Id = Guid.NewGuid(); _chapters[chapter.Id] = chapter; return(Task.FromResult <object>(null)); }