add supplier repo and suppliercreationdto

This commit is contained in:
2023-06-09 13:04:59 +02:00
parent 7b1aaacfb5
commit f5c030df01
14 changed files with 207 additions and 35 deletions

View File

@@ -1,10 +1,5 @@
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;
@@ -12,7 +7,7 @@ public sealed class RepoDbContext : DbContext
{
public RepoDbContext(DbContextOptions options)
: base (options)
: base(options)
{
}

View File

@@ -1,4 +1,7 @@
using System;
using AB.Domain.Entities;
using AB.Domain.Repositories;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -6,9 +9,33 @@ using System.Threading.Tasks;
namespace AB.Persistence.Repos;
public class SupplierRepository
public class SupplierRepository : ISupplierRepository
{
private readonly RepoDbContext _dbContext;
public SupplierRepository(RepoDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task<IEnumerable<Supplier>> GetAllAsync(CancellationToken cancellationToken)
{
return await _dbContext.Suppliers.ToListAsync(cancellationToken);
}
public async Task<Supplier> GetByIdAsync(Guid supplierId, CancellationToken cancellationToken)
{
return await _dbContext.Suppliers.FirstOrDefaultAsync(x => x.SupplierId == supplierId, cancellationToken);
}
public void Insert(Supplier supplier)
{
_dbContext.Add(supplier);
}
public void Remove(Supplier supplier)
{
_dbContext.Suppliers.Remove(supplier);
}
}