working customer post, get and delete

This commit is contained in:
2023-06-07 14:47:00 +02:00
parent ad998e0499
commit c805ce20a8
26 changed files with 448 additions and 142 deletions

View File

@@ -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>

View 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; }
}

View 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);
}
}

View 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
{
}

View 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);
}
}