Allow amateur performer profiles
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
f1c23965b2
commit
0728d2a3f7
20 changed files with 217 additions and 29 deletions
|
|
@ -66,7 +66,7 @@ namespace Yavsc.Controllers
|
|||
|
||||
// PUT: api/Estimate/5
|
||||
[HttpPut("{id}"), Produces("application/json")]
|
||||
public IActionResult PutEstimate(long id, [FromBody] Estimate estimate)
|
||||
public async Task<IActionResult> PutEstimate(long id, [FromBody] Estimate estimate)
|
||||
{
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
|
|
@ -88,6 +88,11 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
if (!await CanIssueEstimatesAsync(estimate.OwnerId))
|
||||
{
|
||||
return Conflict(new { Error = "A business registration is required to issue or edit estimates." });
|
||||
}
|
||||
|
||||
var entry = _context.Attach(estimate);
|
||||
try
|
||||
{
|
||||
|
|
@ -110,7 +115,7 @@ namespace Yavsc.Controllers
|
|||
|
||||
// POST: api/Estimate
|
||||
[HttpPost, Produces("application/json")]
|
||||
public IActionResult PostEstimate([FromBody] Estimate estimate)
|
||||
public async Task<IActionResult> PostEstimate([FromBody] Estimate estimate)
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
if (estimate.OwnerId == null) estimate.OwnerId = uid;
|
||||
|
|
@ -124,6 +129,11 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
if (!await CanIssueEstimatesAsync(estimate.OwnerId))
|
||||
{
|
||||
return Conflict(new { Error = "A business registration is required to issue estimates." });
|
||||
}
|
||||
|
||||
if (estimate.CommandId != null)
|
||||
{
|
||||
var query = _context.NominativeServiceCommands
|
||||
|
|
@ -334,5 +344,19 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
return _context.Estimates.Count(e => e.Id == id) > 0;
|
||||
}
|
||||
|
||||
private Task<bool> CanIssueEstimatesAsync(string? performerId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(performerId))
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
return _context.Performers
|
||||
.AsNoTracking()
|
||||
.AnyAsync(profile => profile.PerformerId == performerId
|
||||
&& profile.SIREN != null
|
||||
&& profile.SIREN.Trim() != "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -616,6 +616,12 @@ namespace Yavsc.WebApi.Controllers
|
|||
return BadRequest(new { error = "Payload is required." });
|
||||
}
|
||||
|
||||
model.SIREN = model.SIREN?.Trim() ?? string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(model.ExerciseCountryCode))
|
||||
{
|
||||
model.ExerciseCountryCode = "fr";
|
||||
}
|
||||
|
||||
var uid = User.GetUserId();
|
||||
if (string.IsNullOrWhiteSpace(uid))
|
||||
{
|
||||
|
|
@ -652,11 +658,6 @@ namespace Yavsc.WebApi.Controllers
|
|||
return NotFound();
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(model.ExerciseCountryCode))
|
||||
{
|
||||
model.ExerciseCountryCode = "fr";
|
||||
}
|
||||
|
||||
var profile = await _dbContext.Performers.FirstOrDefaultAsync(p => p.PerformerId == uid);
|
||||
if (profile is null)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue