mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-10-03 08:03:17 +00:00
76 lines
2.3 KiB
C#
76 lines
2.3 KiB
C#
|
|
using Microsoft.AspNetCore.Authorization;
|
||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using ProposalSystem.Domain.Entities;
|
||
|
|
using ProposalSystem.Infrastructure.Data;
|
||
|
|
|
||
|
|
namespace ProposalSystem.Api.Controllers;
|
||
|
|
|
||
|
|
[ApiController]
|
||
|
|
[Route("api/vendor-proposals")]
|
||
|
|
[Authorize]
|
||
|
|
public class VendorProposalsController : ControllerBase
|
||
|
|
{
|
||
|
|
private readonly ProposalDbContext _db;
|
||
|
|
|
||
|
|
public VendorProposalsController(ProposalDbContext db)
|
||
|
|
{
|
||
|
|
_db = db;
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPut("{id:guid}")]
|
||
|
|
public async Task<IActionResult> Update(Guid id, [FromBody] UpdateVendorProposalRequest request, CancellationToken ct)
|
||
|
|
{
|
||
|
|
var vendor = await _db.VendorProposals.FindAsync(new object[] { id }, ct);
|
||
|
|
if (vendor == null) return NotFound();
|
||
|
|
|
||
|
|
if (request.VendorName != null)
|
||
|
|
vendor.VendorName = request.VendorName;
|
||
|
|
|
||
|
|
if (request.ExtractedData != null)
|
||
|
|
vendor.ExtractedData = request.ExtractedData;
|
||
|
|
|
||
|
|
if (request.TotalVendorCost.HasValue)
|
||
|
|
vendor.TotalVendorCost = request.TotalVendorCost.Value;
|
||
|
|
|
||
|
|
if (request.ProcessingStatus != null && Enum.TryParse<ProcessingStatus>(request.ProcessingStatus, out var status))
|
||
|
|
vendor.ProcessingStatus = status;
|
||
|
|
|
||
|
|
await _db.SaveChangesAsync(ct);
|
||
|
|
|
||
|
|
if (vendor.TotalVendorCost > 0)
|
||
|
|
{
|
||
|
|
var proposal = await _db.Proposals.FindAsync(new object[] { vendor.ProposalId }, ct);
|
||
|
|
if (proposal != null)
|
||
|
|
{
|
||
|
|
proposal.VendorTotalCost = vendor.TotalVendorCost;
|
||
|
|
await _db.SaveChangesAsync(ct);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return NoContent();
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPut("{id:guid}/status")]
|
||
|
|
public async Task<IActionResult> UpdateStatus(Guid id, [FromBody] UpdateStatusRequest request, CancellationToken ct)
|
||
|
|
{
|
||
|
|
var vendor = await _db.VendorProposals.FindAsync(new object[] { id }, ct);
|
||
|
|
if (vendor == null) return NotFound();
|
||
|
|
|
||
|
|
if (Enum.TryParse<ProcessingStatus>(request.ProcessingStatus, out var status))
|
||
|
|
vendor.ProcessingStatus = status;
|
||
|
|
|
||
|
|
await _db.SaveChangesAsync(ct);
|
||
|
|
return NoContent();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public record UpdateVendorProposalRequest(
|
||
|
|
string? VendorName,
|
||
|
|
string? ExtractedData,
|
||
|
|
decimal? TotalVendorCost,
|
||
|
|
string? ProcessingStatus
|
||
|
|
);
|
||
|
|
|
||
|
|
public record UpdateStatusRequest(string ProcessingStatus);
|