Refactor DTOs, add Blazor WASM frontend, enable CORS

- Split `CatalogDto` into `CatalogReadDto` and `CatalogWriteDto` for clear separation of read/write operations in both backend and frontend.
- Updated API controllers, services, and AutoMapper profiles to use new DTOs; ensured audit fields are set in service layer.
- Enabled CORS in the API project to support Blazor WASM frontend.
- Added new Blazor WebAssembly project (`DbFirst.BlazorWasm`) with catalog management UI, API client, Bootstrap v5.1.0 styling, and configuration-driven API base URL.
- Included `bootstrap.min.css` and its source map for frontend styling and easier debugging.
- Updated solution file to include new project and support multiple build configurations.
- Result: improved API design, clean DTO separation, and a modern interactive frontend for catalog management.
This commit is contained in:
OlgunR
2026-01-13 10:15:01 +01:00
parent ce40abe20f
commit 14e1cbc3b6
29 changed files with 860 additions and 25 deletions

View File

@@ -15,14 +15,14 @@ public class CatalogsController : ControllerBase
}
[HttpGet]
public async Task<ActionResult<IEnumerable<CatalogDto>>> GetAll(CancellationToken cancellationToken)
public async Task<ActionResult<IEnumerable<CatalogReadDto>>> GetAll(CancellationToken cancellationToken)
{
var result = await _service.GetAllAsync(cancellationToken);
return Ok(result);
}
[HttpGet("{id:int}")]
public async Task<ActionResult<CatalogDto>> GetById(int id, CancellationToken cancellationToken)
public async Task<ActionResult<CatalogReadDto>> GetById(int id, CancellationToken cancellationToken)
{
var result = await _service.GetByIdAsync(id, cancellationToken);
if (result == null)
@@ -33,14 +33,14 @@ public class CatalogsController : ControllerBase
}
[HttpPost]
public async Task<ActionResult<CatalogDto>> Create(CatalogDto dto, CancellationToken cancellationToken)
public async Task<ActionResult<CatalogReadDto>> Create(CatalogWriteDto dto, CancellationToken cancellationToken)
{
var created = await _service.CreateAsync(dto, cancellationToken);
return CreatedAtAction(nameof(GetById), new { id = created.Guid }, created);
}
[HttpPut("{id:int}")]
public async Task<IActionResult> Update(int id, CatalogDto dto, CancellationToken cancellationToken)
public async Task<IActionResult> Update(int id, CatalogWriteDto dto, CancellationToken cancellationToken)
{
var updated = await _service.UpdateAsync(id, dto, cancellationToken);
if (!updated)
@@ -51,10 +51,9 @@ public class CatalogsController : ControllerBase
}
[HttpPut("sp/{id:int}")]
public async Task<ActionResult<CatalogDto>> UpdateWithStoredProcedure(int id, CatalogDto dto, CancellationToken cancellationToken)
public async Task<ActionResult<CatalogReadDto>> UpdateWithStoredProcedure(int id, CatalogWriteDto dto, CancellationToken cancellationToken)
{
dto.Guid = id;
var updated = await _service.UpdateWithStoredProcedureAsync(dto, cancellationToken);
var updated = await _service.UpdateWithStoredProcedureAsync(id, dto, cancellationToken);
if (updated == null)
{
return NotFound();

View File

@@ -12,6 +12,16 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
@@ -30,7 +40,7 @@ if (app.Environment.IsDevelopment())
}
app.UseHttpsRedirection();
app.UseCors();
app.UseAuthorization();
app.MapControllers();