working customer post, get and delete
This commit is contained in:
@@ -6,4 +6,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AB.Domain\AB.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
25
AB.Persistence/RepoDbContext.cs
Normal file
25
AB.Persistence/RepoDbContext.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using AB.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AB.Persistence;
|
||||
|
||||
public sealed class RepoDbContext : DbContext
|
||||
{
|
||||
|
||||
public RepoDbContext(DbContextOptions options)
|
||||
: base (options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<Customer> Customers { get; set; }
|
||||
|
||||
public DbSet<Supplier> Suppliers { get; set; }
|
||||
|
||||
public DbSet<Product> Products { get; set; }
|
||||
|
||||
}
|
||||
36
AB.Persistence/Repos/CustomerRepository.cs
Normal file
36
AB.Persistence/Repos/CustomerRepository.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using AB.Domain.Entities;
|
||||
using AB.Domain.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AB.Persistence.Repos;
|
||||
|
||||
public class CustomerRepository : ICustomerRepository
|
||||
{
|
||||
|
||||
private readonly RepoDbContext _dbContext;
|
||||
|
||||
public CustomerRepository(RepoDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Customer>> GetAllAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await _dbContext.Customers.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<Customer> GetByIdAsync(Guid customerId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _dbContext.Customers.FirstOrDefaultAsync(x => x.CustomerId == customerId, cancellationToken);
|
||||
}
|
||||
|
||||
public void Insert(Customer customer)
|
||||
{
|
||||
_dbContext.Customers.Add(customer);
|
||||
}
|
||||
|
||||
public void Remove(Customer customer)
|
||||
{
|
||||
_dbContext.Customers.Remove(customer);
|
||||
}
|
||||
}
|
||||
14
AB.Persistence/Repos/SupplierRepository.cs
Normal file
14
AB.Persistence/Repos/SupplierRepository.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AB.Persistence.Repos;
|
||||
|
||||
public class SupplierRepository
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
19
AB.Persistence/Repos/UnitOfWork.cs
Normal file
19
AB.Persistence/Repos/UnitOfWork.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using AB.Domain.Repositories;
|
||||
|
||||
namespace AB.Persistence.Repos;
|
||||
|
||||
public class UnitOfWork : IUnitOfWork
|
||||
{
|
||||
|
||||
private readonly RepoDbContext _dbContext;
|
||||
|
||||
public UnitOfWork(RepoDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public Task<int> SaveChangesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return _dbContext.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user