Refactor to use VwmyCatalog as primary catalog entity

Replaced all usage of the Catalog entity with VwmyCatalog across application, domain, and infrastructure layers. Updated AutoMapper profiles, repository interfaces, and service logic to use VwmyCatalog. Removed the obsolete Catalog entity and related mapping profiles. Moved VwmyCatalog to the Domain.Entities namespace and cleaned up project structure. This change simplifies the domain model and eliminates redundant entity definitions.
This commit is contained in:
OlgunR
2026-01-14 15:01:13 +01:00
parent ccd97fe9d6
commit 6caf3a4c07
9 changed files with 47 additions and 80 deletions

View File

@@ -1,4 +1,4 @@
using DbFirst.Infrastructure.ScaffoldEntities;
using DbFirst.Domain.Entities;
using Microsoft.EntityFrameworkCore;
namespace DbFirst.Infrastructure;

View File

@@ -1,13 +0,0 @@
using AutoMapper;
using DbFirst.Domain.DomainEntities;
using DbFirst.Infrastructure.ScaffoldEntities;
namespace DbFirst.Infrastructure.Mappings;
public class CatalogInfrastructureProfile : Profile
{
public CatalogInfrastructureProfile()
{
CreateMap<VwmyCatalog, Catalog>();
}
}

View File

@@ -1,7 +1,5 @@
using AutoMapper;
using DbFirst.Domain.DomainEntities;
using DbFirst.Domain.Repositories;
using DbFirst.Infrastructure.ScaffoldEntities;
using DbFirst.Domain.Entities;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using System.Data;
@@ -11,27 +9,23 @@ namespace DbFirst.Infrastructure.Repositories;
public class CatalogRepository : ICatalogRepository
{
private readonly ApplicationDbContext _db;
private readonly IMapper _mapper;
public CatalogRepository(ApplicationDbContext db, IMapper mapper)
public CatalogRepository(ApplicationDbContext db)
{
_db = db;
_mapper = mapper;
}
public async Task<List<Catalog>> GetAllAsync(CancellationToken cancellationToken = default)
public async Task<List<VwmyCatalog>> GetAllAsync(CancellationToken cancellationToken = default)
{
var viewRows = await _db.VwmyCatalogs.AsNoTracking().ToListAsync(cancellationToken);
return _mapper.Map<List<Catalog>>(viewRows);
return await _db.VwmyCatalogs.AsNoTracking().ToListAsync(cancellationToken);
}
public async Task<Catalog?> GetByIdAsync(int id, CancellationToken cancellationToken = default)
public async Task<VwmyCatalog?> GetByIdAsync(int id, CancellationToken cancellationToken = default)
{
var viewRow = await _db.VwmyCatalogs.AsNoTracking().FirstOrDefaultAsync(x => x.Guid == id, cancellationToken);
return viewRow == null ? null : _mapper.Map<Catalog>(viewRow);
return await _db.VwmyCatalogs.AsNoTracking().FirstOrDefaultAsync(x => x.Guid == id, cancellationToken);
}
public async Task<Catalog> AddAsync(Catalog catalog, CancellationToken cancellationToken = default)
public async Task<VwmyCatalog> AddAsync(VwmyCatalog catalog, CancellationToken cancellationToken = default)
{
var created = await UpsertWithStoredProcedureAsync(catalog, cancellationToken);
if (created == null)
@@ -42,7 +36,7 @@ public class CatalogRepository : ICatalogRepository
return created;
}
public async Task<bool> UpdateAsync(int id, Catalog catalog, CancellationToken cancellationToken = default)
public async Task<bool> UpdateAsync(int id, VwmyCatalog catalog, CancellationToken cancellationToken = default)
{
var existing = await _db.VwmyCatalogs.AsNoTracking().AnyAsync(x => x.Guid == id, cancellationToken);
if (!existing)
@@ -55,7 +49,7 @@ public class CatalogRepository : ICatalogRepository
return updated != null;
}
public async Task<Catalog?> UpdateWithStoredProcedureAsync(Catalog catalog, CancellationToken cancellationToken = default)
public async Task<VwmyCatalog?> UpdateWithStoredProcedureAsync(VwmyCatalog catalog, CancellationToken cancellationToken = default)
{
if (catalog.Guid == 0)
{
@@ -93,7 +87,7 @@ public class CatalogRepository : ICatalogRepository
return await DeleteAsync(id, cancellationToken);
}
private async Task<Catalog?> UpsertWithStoredProcedureAsync(Catalog catalog, CancellationToken cancellationToken)
private async Task<VwmyCatalog?> UpsertWithStoredProcedureAsync(VwmyCatalog catalog, CancellationToken cancellationToken)
{
var guidParam = new SqlParameter("@GUID", SqlDbType.Int)
{
@@ -116,7 +110,6 @@ public class CatalogRepository : ICatalogRepository
}
var guid = (int)guidParam.Value;
var viewRow = await _db.VwmyCatalogs.AsNoTracking().FirstOrDefaultAsync(x => x.Guid == guid, cancellationToken);
return viewRow == null ? null : _mapper.Map<Catalog>(viewRow);
return await _db.VwmyCatalogs.AsNoTracking().FirstOrDefaultAsync(x => x.Guid == guid, cancellationToken);
}
}

View File

@@ -1,18 +0,0 @@
namespace DbFirst.Infrastructure.ScaffoldEntities;
public partial class VwmyCatalog
{
public int Guid { get; set; }
public string CatTitle { get; set; } = null!;
public string CatString { get; set; } = null!;
public string AddedWho { get; set; } = null!;
public DateTime AddedWhen { get; set; }
public string? ChangedWho { get; set; }
public DateTime? ChangedWhen { get; set; }
}