Skip to content

Commit 60c0872

Browse files
BROKERS: Delete Book
1 parent 03a4dcb commit 60c0872

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

LibraryManagement.Api/Brokers/Storages/IStorageBroker.Book.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ public partial interface IStorageBroker
1313
IQueryable<Book> SelectAllBooks();
1414
ValueTask<Book> SelectBookByIdAsync(Guid bookId);
1515
ValueTask<Book> UpdateBookAsync(Book book);
16+
ValueTask<Book> DeleteBookAsync(Book book);
1617
}
1718
}

LibraryManagement.Api/Brokers/Storages/StorageBroker.Book.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,8 @@ public async ValueTask<Book> SelectBookByIdAsync(Guid bookId)
3333

3434
public async ValueTask<Book> UpdateBookAsync(Book book) =>
3535
await UpdateAsync(book);
36+
37+
public async ValueTask<Book> DeleteBookAsync(Book book) =>
38+
await DeleteAsync(book);
3639
}
3740
}

LibraryManagement.Api/Brokers/Storages/StorageBroker.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ public async ValueTask<T> UpdateAsync<T>(T @object)
4343
return @object;
4444
}
4545

46+
public async ValueTask<T> DeleteAsync<T>(T @object)
47+
{
48+
var broker = new StorageBroker(configuration);
49+
broker.Entry(@object).State = EntityState.Deleted;
50+
await broker.SaveChangesAsync();
51+
52+
return @object;
53+
}
54+
4655
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
4756
{
4857
string connectionString =

0 commit comments

Comments
 (0)