Skip to content

Commit b8abbbb

Browse files
Merge pull request #18 from DilmurodDeveloper/users/DilmurodDeveloper/brokers-book-insert
BROKERS: Insert Book
2 parents 6c785fc + a82f9c2 commit b8abbbb

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

LibraryManagement.Api/Brokers/Storages/StorageBroker.ReaderBook.cs renamed to LibraryManagement.Api/Brokers/Storages/IStorageBroker.Book.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
// Free To Use To Build Reliable Library Management Solutions
44
//-----------------------------------------------------------
55

6-
using LibraryManagement.Api.Models.Foundations.ReaderBooks;
7-
using Microsoft.EntityFrameworkCore;
6+
using LibraryManagement.Api.Models.Foundations.Books;
87

98
namespace LibraryManagement.Api.Brokers.Storages
109
{
11-
public partial class StorageBroker
10+
public partial interface IStorageBroker
1211
{
13-
public DbSet<ReaderBook> ReaderBooks { get; set; }
12+
ValueTask<Book> InsertBookAsync(Book book);
1413
}
1514
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//-----------------------------------------------------------
2+
// Copyright (c) Coalition of Good-Hearted Engineers
3+
// Free To Use To Build Reliable Library Management Solutions
4+
//-----------------------------------------------------------
5+
6+
namespace LibraryManagement.Api.Brokers.Storages
7+
{
8+
public partial interface IStorageBroker
9+
{ }
10+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ namespace LibraryManagement.Api.Brokers.Storages
1111
public partial class StorageBroker
1212
{
1313
public DbSet<Book> Books { get; set; }
14+
15+
public async ValueTask<Book> InsertBookAsync(Book book) =>
16+
await InsertAsync(book);
1417
}
1518
}

LibraryManagement.Api/Brokers/Storages/StorageBroker.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace LibraryManagement.Api.Brokers.Storages
1111
{
12-
public partial class StorageBroker : EFxceptionsContext
12+
public partial class StorageBroker : EFxceptionsContext, IStorageBroker
1313
{
1414
private readonly IConfiguration configuration;
1515

@@ -19,6 +19,15 @@ public StorageBroker(IConfiguration configuration)
1919
this.Database.Migrate();
2020
}
2121

22+
public async ValueTask<T> InsertAsync<T>(T @object)
23+
{
24+
var broker = new StorageBroker(this.configuration);
25+
broker.Entry(@object).State = EntityState.Added;
26+
await broker.SaveChangesAsync();
27+
28+
return @object;
29+
}
30+
2231
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2332
{
2433
string connectionString =

0 commit comments

Comments
 (0)