Refactor error handling in controllers
Removed try-catch blocks from various controller methods to simplify error handling and allow exceptions to propagate naturally. Streamlined error logging and response handling using the `ThenAsync` method, enhancing code readability and reducing redundancy. Adjusted conditional checks for improved clarity.
This commit is contained in:
parent
972b258706
commit
5ce6c25393
@ -118,16 +118,8 @@ public partial class AuthController : ControllerBase
|
|||||||
[HttpPost("logout")]
|
[HttpPost("logout")]
|
||||||
public async Task<IActionResult> Logout()
|
public async Task<IActionResult> Logout()
|
||||||
{
|
{
|
||||||
try
|
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
{
|
return Ok();
|
||||||
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Unexpected error occurred.\n{ErrorMessage}", ex.Message);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -63,23 +63,15 @@ public class EmailTemplateController : ControllerBase
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> Get([FromQuery] ReadEmailTemplateQuery? emailTemplate = null)
|
public async Task<IActionResult> Get([FromQuery] ReadEmailTemplateQuery? emailTemplate = null)
|
||||||
{
|
{
|
||||||
try
|
if (emailTemplate is null || (emailTemplate.Id is null && emailTemplate.Type is null))
|
||||||
{
|
{
|
||||||
if (emailTemplate is null || (emailTemplate.Id is null && emailTemplate.Type is null))
|
var temps = await _repository.ReadAllAsync();
|
||||||
{
|
return Ok(_mapper.Map<IEnumerable<EmailTemplateDto>>(temps));
|
||||||
var temps = await _repository.ReadAllAsync();
|
|
||||||
return Ok(_mapper.Map<IEnumerable<EmailTemplateDto>>(temps));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var temp = await _mediator.Send(emailTemplate);
|
|
||||||
return temp is null ? NotFound() : Ok(temp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
else
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "{Message}", ex.Message);
|
var temp = await _mediator.Send(emailTemplate);
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
return temp is null ? NotFound() : Ok(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,33 +99,20 @@ public class EmailTemplateController : ControllerBase
|
|||||||
[HttpPut]
|
[HttpPut]
|
||||||
public async Task<IActionResult> Update([FromQuery] EmailTemplateQuery? temp = null, [FromBody] UpdateEmailTemplateCommand? update = null)
|
public async Task<IActionResult> Update([FromQuery] EmailTemplateQuery? temp = null, [FromBody] UpdateEmailTemplateCommand? update = null)
|
||||||
{
|
{
|
||||||
try
|
if (update is null)
|
||||||
{
|
{
|
||||||
if (update is null)
|
await _mediator.Send(new ResetEmailTemplateCommand(temp));
|
||||||
{
|
return Ok();
|
||||||
await _mediator.Send(new ResetEmailTemplateCommand(temp));
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
else if(temp is null)
|
|
||||||
{
|
|
||||||
return BadRequest("No both id and type");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
update.EmailTemplateQuery = temp;
|
|
||||||
await _mediator.Send(update);
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(NotFoundException)
|
else if (temp is null)
|
||||||
{
|
{
|
||||||
return BadRequest();
|
return BadRequest("No both id and type");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
else
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "An unexpected error occurred. {message}", ex.Message);
|
update.EmailTemplateQuery = temp;
|
||||||
return new StatusCodeResult(StatusCodes.Status500InternalServerError);
|
await _mediator.Send(update);
|
||||||
|
return Ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,37 +61,29 @@ public class EnvelopeController : ControllerBase
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> GetAsync([FromQuery] ReadEnvelopeQuery envelope)
|
public async Task<IActionResult> GetAsync([FromQuery] ReadEnvelopeQuery envelope)
|
||||||
{
|
{
|
||||||
try
|
if (User.GetId() is int intId)
|
||||||
|
return await _envelopeService.ReadByUserAsync(intId, min_status: envelope.Status, max_status: envelope.Status).ThenAsync(
|
||||||
|
Success: envelopes =>
|
||||||
|
{
|
||||||
|
if (envelope.Id is int id)
|
||||||
|
envelopes = envelopes.Where(e => e.Id == id);
|
||||||
|
|
||||||
|
if (envelope.Status is int status)
|
||||||
|
envelopes = envelopes.Where(e => e.Status == status);
|
||||||
|
|
||||||
|
if (envelope.Uuid is string uuid)
|
||||||
|
envelopes = envelopes.Where(e => e.Uuid == uuid);
|
||||||
|
|
||||||
|
return Ok(envelopes);
|
||||||
|
},
|
||||||
|
Fail: IActionResult (msg, ntc) =>
|
||||||
|
{
|
||||||
|
_logger.LogNotice(ntc);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
|
});
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (User.GetId() is int intId)
|
_logger.LogError("Trotz erfolgreicher Autorisierung wurde die Benutzer-ID nicht als Ganzzahl erkannt. Dies könnte auf eine fehlerhafte Erstellung der Anspruchsliste zurückzuführen sein.");
|
||||||
return await _envelopeService.ReadByUserAsync(intId, min_status: envelope.Status, max_status: envelope.Status).ThenAsync(
|
|
||||||
Success: envelopes =>
|
|
||||||
{
|
|
||||||
if(envelope.Id is int id)
|
|
||||||
envelopes = envelopes.Where(e => e.Id == id);
|
|
||||||
|
|
||||||
if(envelope.Status is int status)
|
|
||||||
envelopes = envelopes.Where(e => e.Status == status);
|
|
||||||
|
|
||||||
if (envelope.Uuid is string uuid)
|
|
||||||
envelopes = envelopes.Where(e => e.Uuid == uuid);
|
|
||||||
|
|
||||||
return Ok(envelopes);
|
|
||||||
},
|
|
||||||
Fail: IActionResult (msg, ntc) =>
|
|
||||||
{
|
|
||||||
_logger.LogNotice(ntc);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
});
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.LogError("Trotz erfolgreicher Autorisierung wurde die Benutzer-ID nicht als Ganzzahl erkannt. Dies könnte auf eine fehlerhafte Erstellung der Anspruchsliste zurückzuführen sein.");
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "{Message}", ex.Message);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,43 +100,35 @@ public class EnvelopeController : ControllerBase
|
|||||||
[HttpGet("doc-result")]
|
[HttpGet("doc-result")]
|
||||||
public async Task<IActionResult> GetDocResultAsync([FromQuery] int id, [FromQuery] bool view = false)
|
public async Task<IActionResult> GetDocResultAsync([FromQuery] int id, [FromQuery] bool view = false)
|
||||||
{
|
{
|
||||||
try
|
if (User.GetId() is int intId)
|
||||||
{
|
return await _envelopeService.ReadByUserAsync(intId).ThenAsync(
|
||||||
if (User.GetId() is int intId)
|
Success: envelopes =>
|
||||||
return await _envelopeService.ReadByUserAsync(intId).ThenAsync(
|
{
|
||||||
Success: envelopes =>
|
var envelope = envelopes.Where(e => e.Id == id).FirstOrDefault();
|
||||||
{
|
|
||||||
var envelope = envelopes.Where(e => e.Id == id).FirstOrDefault();
|
|
||||||
|
|
||||||
if (envelope is null)
|
if (envelope is null)
|
||||||
return NotFound("Envelope not available.");
|
return NotFound("Envelope not available.");
|
||||||
else if (envelope?.DocResult is null)
|
else if (envelope?.DocResult is null)
|
||||||
return NotFound("The document has not been fully signed or the result has not yet been released.");
|
return NotFound("The document has not been fully signed or the result has not yet been released.");
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if (view)
|
|
||||||
{
|
|
||||||
Response.Headers.Append("Content-Disposition", "inline; filename=\"" + envelope.Uuid + ".pdf\"");
|
|
||||||
return File(envelope.DocResult, "application/pdf");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return File(envelope.DocResult, "application/pdf", $"{envelope.Uuid}.pdf");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Fail: IActionResult (msg, ntc) =>
|
|
||||||
{
|
{
|
||||||
_logger.LogNotice(ntc);
|
if (view)
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
{
|
||||||
});
|
Response.Headers.Append("Content-Disposition", "inline; filename=\"" + envelope.Uuid + ".pdf\"");
|
||||||
else
|
return File(envelope.DocResult, "application/pdf");
|
||||||
{
|
}
|
||||||
_logger.LogError("Trotz erfolgreicher Autorisierung wurde die Benutzer-ID nicht als Ganzzahl erkannt. Dies könnte auf eine fehlerhafte Erstellung der Anspruchsliste zurückzuführen sein.");
|
else
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
return File(envelope.DocResult, "application/pdf", $"{envelope.Uuid}.pdf");
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
catch (Exception ex)
|
Fail: IActionResult (msg, ntc) =>
|
||||||
|
{
|
||||||
|
_logger.LogNotice(ntc);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
|
});
|
||||||
|
else
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "{Message}", ex.Message);
|
_logger.LogError("Trotz erfolgreicher Autorisierung wurde die Benutzer-ID nicht als Ganzzahl erkannt. Dies könnte auf eine fehlerhafte Erstellung der Anspruchsliste zurückzuführen sein.");
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,23 +143,15 @@ public class EnvelopeController : ControllerBase
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> CreateAsync([FromQuery] CreateEnvelopeCommand envelope)
|
public async Task<IActionResult> CreateAsync([FromQuery] CreateEnvelopeCommand envelope)
|
||||||
{
|
{
|
||||||
try
|
envelope.UserId = User.GetId();
|
||||||
|
var res = await _mediator.Send(envelope);
|
||||||
|
|
||||||
|
if (res is null)
|
||||||
{
|
{
|
||||||
envelope.UserId = User.GetId();
|
_logger.LogError("Failed to create envelope. Envelope details: {EnvelopeDetails}", JsonConvert.SerializeObject(envelope));
|
||||||
var res = await _mediator.Send(envelope);
|
|
||||||
|
|
||||||
if (res is null)
|
|
||||||
{
|
|
||||||
_logger.LogError("Failed to create envelope. Envelope details: {EnvelopeDetails}", JsonConvert.SerializeObject(envelope));
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return Ok(res);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "{Message}", ex.Message);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return Ok(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,37 +84,29 @@ public class EnvelopeReceiverController : ControllerBase
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> GetEnvelopeReceiver([FromQuery] ReadEnvelopeReceiverQuery envelopeReceiver)
|
public async Task<IActionResult> GetEnvelopeReceiver([FromQuery] ReadEnvelopeReceiverQuery envelopeReceiver)
|
||||||
{
|
{
|
||||||
try
|
var username = User.GetUsernameOrDefault();
|
||||||
{
|
|
||||||
var username = User.GetUsernameOrDefault();
|
|
||||||
|
|
||||||
if (username is null)
|
if (username is null)
|
||||||
{
|
|
||||||
_logger.LogError(@"Envelope Receiver dto cannot be sent because username claim is null. Potential authentication and authorization error. The value of other claims are [id: {id}], [username: {username}], [name: {name}], [prename: {prename}], [email: {email}].",
|
|
||||||
User.GetId(), User.GetUsernameOrDefault(), User.GetNameOrDefault(), User.GetPrenameOrDefault(), User.GetEmailOrDefault());
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await _erService.ReadByUsernameAsync(
|
|
||||||
username: username,
|
|
||||||
min_status: envelopeReceiver.Status?.Min,
|
|
||||||
max_status:envelopeReceiver.Status?.Max,
|
|
||||||
envelopeQuery: envelopeReceiver.Envelope,
|
|
||||||
receiverQuery: envelopeReceiver.Receiver,
|
|
||||||
ignore_statuses: envelopeReceiver.Status?.Ignore ?? Array.Empty<int>())
|
|
||||||
.ThenAsync(
|
|
||||||
Success: Ok,
|
|
||||||
Fail: IActionResult (msg, ntc) =>
|
|
||||||
{
|
|
||||||
_logger.LogNotice(ntc);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError, msg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "An unexpected error occurred. {message}", ex.Message);
|
_logger.LogError(@"Envelope Receiver dto cannot be sent because username claim is null. Potential authentication and authorization error. The value of other claims are [id: {id}], [username: {username}], [name: {name}], [prename: {prename}], [email: {email}].",
|
||||||
return new StatusCodeResult(StatusCodes.Status500InternalServerError);
|
User.GetId(), User.GetUsernameOrDefault(), User.GetNameOrDefault(), User.GetPrenameOrDefault(), User.GetEmailOrDefault());
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return await _erService.ReadByUsernameAsync(
|
||||||
|
username: username,
|
||||||
|
min_status: envelopeReceiver.Status?.Min,
|
||||||
|
max_status: envelopeReceiver.Status?.Max,
|
||||||
|
envelopeQuery: envelopeReceiver.Envelope,
|
||||||
|
receiverQuery: envelopeReceiver.Receiver,
|
||||||
|
ignore_statuses: envelopeReceiver.Status?.Ignore ?? Array.Empty<int>())
|
||||||
|
.ThenAsync(
|
||||||
|
Success: Ok,
|
||||||
|
Fail: IActionResult (msg, ntc) =>
|
||||||
|
{
|
||||||
|
_logger.LogNotice(ntc);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError, msg);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -133,24 +125,16 @@ public class EnvelopeReceiverController : ControllerBase
|
|||||||
[HttpGet("salute")]
|
[HttpGet("salute")]
|
||||||
public async Task<IActionResult> GetReceiverName([FromQuery] ReadReceiverNameQuery receiverName)
|
public async Task<IActionResult> GetReceiverName([FromQuery] ReadReceiverNameQuery receiverName)
|
||||||
{
|
{
|
||||||
try
|
return await _erService.ReadLastUsedReceiverNameByMail(receiverName.EmailAddress).ThenAsync(
|
||||||
{
|
Success: res => res is null ? Ok(string.Empty) : Ok(res),
|
||||||
return await _erService.ReadLastUsedReceiverNameByMail(receiverName.EmailAddress).ThenAsync(
|
Fail: IActionResult (msg, ntc) =>
|
||||||
Success: res => res is null ? Ok(string.Empty) : Ok(res),
|
{
|
||||||
Fail: IActionResult (msg, ntc) =>
|
if (ntc.HasFlag(Flag.NotFound))
|
||||||
{
|
return NotFound();
|
||||||
if (ntc.HasFlag(Flag.NotFound))
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
_logger.LogNotice(ntc);
|
_logger.LogNotice(ntc);
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "{message}", ex.Message);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -194,44 +178,42 @@ public class EnvelopeReceiverController : ControllerBase
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> CreateAsync([FromBody] CreateEnvelopeReceiverCommand request)
|
public async Task<IActionResult> CreateAsync([FromBody] CreateEnvelopeReceiverCommand request)
|
||||||
{
|
{
|
||||||
try
|
CancellationToken cancel = default;
|
||||||
|
int userId = User.GetId();
|
||||||
|
|
||||||
|
#region Create Envelope
|
||||||
|
var envelope = await _envelopeExecutor.CreateEnvelopeAsync(userId, request.Title, request.Message, request.TFAEnabled, cancel);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Add receivers
|
||||||
|
List<EnvelopeReceiver> sentReceivers = new();
|
||||||
|
List<ReceiverGetOrCreateCommand> unsentReceivers = new();
|
||||||
|
|
||||||
|
foreach (var receiver in request.Receivers)
|
||||||
{
|
{
|
||||||
CancellationToken cancel = default;
|
var envelopeReceiver = await _erExecutor.AddEnvelopeReceiverAsync(envelope.Uuid, receiver.EmailAddress, receiver.Salution, receiver.PhoneNumber, cancel);
|
||||||
int userId = User.GetId();
|
|
||||||
|
|
||||||
#region Create Envelope
|
if (envelopeReceiver is null)
|
||||||
var envelope = await _envelopeExecutor.CreateEnvelopeAsync(userId, request.Title, request.Message, request.TFAEnabled, cancel);
|
unsentReceivers.Add(receiver);
|
||||||
#endregion
|
else
|
||||||
|
sentReceivers.Add(envelopeReceiver);
|
||||||
|
}
|
||||||
|
|
||||||
#region Add receivers
|
var res = _mapper.Map<CreateEnvelopeReceiverResponse>(envelope);
|
||||||
List<EnvelopeReceiver> sentReceivers = new();
|
res.UnsentReceivers = unsentReceivers;
|
||||||
List<ReceiverGetOrCreateCommand> unsentReceivers = new();
|
res.SentReceiver = _mapper.Map<List<ReceiverReadDto>>(sentReceivers.Select(er => er.Receiver));
|
||||||
|
#endregion
|
||||||
|
|
||||||
foreach (var receiver in request.Receivers)
|
#region Add document
|
||||||
{
|
var document = await _documentExecutor.CreateDocumentAsync(request.Document.DataAsBase64, envelope.Uuid, cancel);
|
||||||
var envelopeReceiver = await _erExecutor.AddEnvelopeReceiverAsync(envelope.Uuid, receiver.EmailAddress, receiver.Salution, receiver.PhoneNumber, cancel);
|
|
||||||
|
|
||||||
if (envelopeReceiver is null)
|
if (document is null)
|
||||||
unsentReceivers.Add(receiver);
|
return StatusCode(StatusCodes.Status500InternalServerError, "Document creation is failed.");
|
||||||
else
|
#endregion
|
||||||
sentReceivers.Add(envelopeReceiver);
|
|
||||||
}
|
|
||||||
|
|
||||||
var res = _mapper.Map<CreateEnvelopeReceiverResponse>(envelope);
|
#region Add document element
|
||||||
res.UnsentReceivers = unsentReceivers;
|
// @DOC_ID, @RECEIVER_ID, @POSITION_X, @POSITION_Y, @PAGE
|
||||||
res.SentReceiver = _mapper.Map<List<ReceiverReadDto>>(sentReceivers.Select(er => er.Receiver));
|
string sql = @"
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Add document
|
|
||||||
var document = await _documentExecutor.CreateDocumentAsync(request.Document.DataAsBase64, envelope.Uuid, cancel);
|
|
||||||
|
|
||||||
if(document is null)
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError, "Document creation is failed.");
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Add document element
|
|
||||||
// @DOC_ID, @RECEIVER_ID, @POSITION_X, @POSITION_Y, @PAGE
|
|
||||||
string sql = @"
|
|
||||||
DECLARE @OUT_SUCCESS bit;
|
DECLARE @OUT_SUCCESS bit;
|
||||||
|
|
||||||
EXEC [dbo].[PRSIG_API_ADD_DOC_RECEIVER_ELEM]
|
EXEC [dbo].[PRSIG_API_ADD_DOC_RECEIVER_ELEM]
|
||||||
@ -244,30 +226,30 @@ public class EnvelopeReceiverController : ControllerBase
|
|||||||
|
|
||||||
SELECT @OUT_SUCCESS as [@OUT_SUCCESS];";
|
SELECT @OUT_SUCCESS as [@OUT_SUCCESS];";
|
||||||
|
|
||||||
foreach(var rcv in res.SentReceiver)
|
foreach (var rcv in res.SentReceiver)
|
||||||
foreach(var sign in request.Receivers.Where(r => r.EmailAddress == rcv.EmailAddress).FirstOrDefault()?.Signatures ?? Array.Empty<Signature>())
|
foreach (var sign in request.Receivers.Where(r => r.EmailAddress == rcv.EmailAddress).FirstOrDefault()?.Signatures ?? Array.Empty<Signature>())
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = new(_cnnStr))
|
||||||
{
|
{
|
||||||
using (SqlConnection conn = new(_cnnStr))
|
conn.Open();
|
||||||
|
|
||||||
|
var formattedSQL = string.Format(sql, document.Id.ToSqlParam(), rcv.Id.ToSqlParam(), sign.X.ToSqlParam(), sign.Y.ToSqlParam(), sign.Page.ToSqlParam());
|
||||||
|
|
||||||
|
using SqlCommand cmd = new SqlCommand(formattedSQL, conn);
|
||||||
|
cmd.CommandType = CommandType.Text;
|
||||||
|
|
||||||
|
using SqlDataReader reader = cmd.ExecuteReader();
|
||||||
|
if (reader.Read())
|
||||||
{
|
{
|
||||||
conn.Open();
|
bool outSuccess = reader.GetBoolean(0);
|
||||||
|
|
||||||
var formattedSQL = string.Format(sql, document.Id.ToSqlParam(), rcv.Id.ToSqlParam(), sign.X.ToSqlParam(), sign.Y.ToSqlParam(), sign.Page.ToSqlParam());
|
|
||||||
|
|
||||||
using SqlCommand cmd = new SqlCommand(formattedSQL, conn);
|
|
||||||
cmd.CommandType = CommandType.Text;
|
|
||||||
|
|
||||||
using SqlDataReader reader = cmd.ExecuteReader();
|
|
||||||
if (reader.Read())
|
|
||||||
{
|
|
||||||
bool outSuccess = reader.GetBoolean(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Create history
|
#region Create history
|
||||||
// ENV_UID, STATUS_ID, USER_ID,
|
// ENV_UID, STATUS_ID, USER_ID,
|
||||||
string sql_hist = @"
|
string sql_hist = @"
|
||||||
USE [DD_ECM]
|
USE [DD_ECM]
|
||||||
|
|
||||||
DECLARE @OUT_SUCCESS bit;
|
DECLARE @OUT_SUCCESS bit;
|
||||||
@ -280,32 +262,26 @@ public class EnvelopeReceiverController : ControllerBase
|
|||||||
|
|
||||||
SELECT @OUT_SUCCESS as [@OUT_SUCCESS];";
|
SELECT @OUT_SUCCESS as [@OUT_SUCCESS];";
|
||||||
|
|
||||||
using (SqlConnection conn = new(_cnnStr))
|
using (SqlConnection conn = new(_cnnStr))
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
var formattedSQL_hist = string.Format(sql_hist, envelope.Uuid.ToSqlParam(), 1003.ToSqlParam(), userId.ToSqlParam());
|
||||||
|
using (SqlCommand cmd = new SqlCommand(formattedSQL_hist, conn))
|
||||||
{
|
{
|
||||||
conn.Open();
|
cmd.CommandType = CommandType.Text;
|
||||||
var formattedSQL_hist = string.Format(sql_hist, envelope.Uuid.ToSqlParam(), 1003.ToSqlParam(), userId.ToSqlParam());
|
|
||||||
using (SqlCommand cmd = new SqlCommand(formattedSQL_hist, conn))
|
|
||||||
{
|
|
||||||
cmd.CommandType = CommandType.Text;
|
|
||||||
|
|
||||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
if (reader.Read())
|
||||||
{
|
{
|
||||||
if (reader.Read())
|
bool outSuccess = reader.GetBoolean(0);
|
||||||
{
|
|
||||||
bool outSuccess = reader.GetBoolean(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
return Ok(res);
|
return Ok(res);
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "{Message}", ex.Message);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -21,20 +21,12 @@ public class EnvelopeTypeController : ControllerBase
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> GetAllAsync()
|
public async Task<IActionResult> GetAllAsync()
|
||||||
{
|
{
|
||||||
try
|
return await _service.ReadAllAsync().ThenAsync(
|
||||||
{
|
Success: Ok,
|
||||||
return await _service.ReadAllAsync().ThenAsync(
|
Fail: IActionResult (msg, ntc) =>
|
||||||
Success: Ok,
|
{
|
||||||
Fail: IActionResult (msg, ntc) =>
|
_logger.LogNotice(ntc);
|
||||||
{
|
return ntc.HasFlag(Flag.NotFound) ? NotFound() : StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
_logger.LogNotice(ntc);
|
});
|
||||||
return ntc.HasFlag(Flag.NotFound) ? NotFound() : StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "{Message}", ex.Message);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,28 +41,20 @@ public class ReceiverController : CRUDControllerBaseWithErrorHandling<IReceiverS
|
|||||||
if (receiver.Id is null && receiver.EmailAddress is null && receiver.Signature is null)
|
if (receiver.Id is null && receiver.EmailAddress is null && receiver.Signature is null)
|
||||||
return await base.GetAll();
|
return await base.GetAll();
|
||||||
|
|
||||||
try
|
if (receiver.Id is int id)
|
||||||
{
|
return await _service.ReadByIdAsync(id).ThenAsync(
|
||||||
if(receiver.Id is int id)
|
Success: Ok,
|
||||||
return await _service.ReadByIdAsync(id).ThenAsync(
|
Fail: IActionResult (msg, ntc) =>
|
||||||
Success: Ok,
|
{
|
||||||
Fail: IActionResult (msg, ntc) =>
|
return NotFound();
|
||||||
{
|
});
|
||||||
return NotFound();
|
|
||||||
});
|
|
||||||
|
|
||||||
return await _service.ReadByAsync(emailAddress: receiver.EmailAddress, signature: receiver.Signature).ThenAsync(
|
return await _service.ReadByAsync(emailAddress: receiver.EmailAddress, signature: receiver.Signature).ThenAsync(
|
||||||
Success: Ok,
|
Success: Ok,
|
||||||
Fail: IActionResult (msg, ntc) =>
|
Fail: IActionResult (msg, ntc) =>
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "{Message}", ex.Message);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region REMOVED ENDPOINTS
|
#region REMOVED ENDPOINTS
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user