refactor(ReadOnlyController): Globale try-catch-Anweisungen entfernen
This commit is contained in:
parent
903e4678ed
commit
9c6135d208
@ -37,71 +37,63 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
[Obsolete("Use MediatR")]
|
[Obsolete("Use MediatR")]
|
||||||
public async Task<IActionResult> CreateAsync([FromBody] EnvelopeReceiverReadOnlyCreateDto createDto)
|
public async Task<IActionResult> CreateAsync([FromBody] EnvelopeReceiverReadOnlyCreateDto createDto)
|
||||||
{
|
{
|
||||||
try
|
//set AddedWho
|
||||||
|
var authReceiverMail = this.GetAuthReceiverMail();
|
||||||
|
if (authReceiverMail is null)
|
||||||
{
|
{
|
||||||
//set AddedWho
|
_logger.LogError("EmailAddress clam is not found in envelope-receiver-read-only creation process. Create DTO is:\n {dto}", JsonConvert.SerializeObject(createDto));
|
||||||
var authReceiverMail = this.GetAuthReceiverMail();
|
return Unauthorized();
|
||||||
if (authReceiverMail is null)
|
|
||||||
{
|
|
||||||
_logger.LogError("EmailAddress clam is not found in envelope-receiver-read-only creation process. Create DTO is:\n {dto}", JsonConvert.SerializeObject(createDto));
|
|
||||||
return Unauthorized();
|
|
||||||
}
|
|
||||||
|
|
||||||
var envelopeId = this.GetAuthEnvelopeId();
|
|
||||||
if (envelopeId is null)
|
|
||||||
{
|
|
||||||
_logger.LogError("Envelope Id clam is not found in envelope-receiver-read-only creation process. Create DTO is:\n {dto}", JsonConvert.SerializeObject(createDto));
|
|
||||||
return Unauthorized();
|
|
||||||
}
|
|
||||||
|
|
||||||
createDto.AddedWho = authReceiverMail;
|
|
||||||
createDto.EnvelopeId = envelopeId;
|
|
||||||
|
|
||||||
// create entity
|
|
||||||
var creation_res = await _erroService.CreateAsync(createDto: createDto);
|
|
||||||
|
|
||||||
if (creation_res.IsFailed)
|
|
||||||
{
|
|
||||||
_logger.LogNotice(creation_res);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
}
|
|
||||||
|
|
||||||
//read new entity
|
|
||||||
var read_res = await _erroService.ReadByIdAsync(creation_res.Data.Id);
|
|
||||||
if (read_res.IsFailed)
|
|
||||||
{
|
|
||||||
_logger.LogNotice(creation_res);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
}
|
|
||||||
|
|
||||||
var new_erro = read_res.Data;
|
|
||||||
|
|
||||||
//send email two receiver
|
|
||||||
return await _mailService.SendAsync(new_erro).ThenAsync<int, IActionResult>(SuccessAsync: async res =>
|
|
||||||
{
|
|
||||||
//TODO: implement multi-threading to history process (Task)
|
|
||||||
//TODO: remove casting after change the id type
|
|
||||||
var hist_res = await _histService.RecordAsync((int)createDto.EnvelopeId, createDto.AddedWho, EnvelopeStatus.EnvelopeShared);
|
|
||||||
if (hist_res.IsFailed)
|
|
||||||
{
|
|
||||||
_logger.LogError("Although the envelope was sent as read-only, the EnvelopeShared hisotry could not be saved. Create DTO:\n{createDto}", JsonConvert.SerializeObject(createDto));
|
|
||||||
_logger.LogNotice(hist_res.Notices);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok();
|
|
||||||
},
|
|
||||||
|
|
||||||
Fail: (msg, ntc) =>
|
|
||||||
{
|
|
||||||
_logger.LogNotice(ntc);
|
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
|
||||||
|
var envelopeId = this.GetAuthEnvelopeId();
|
||||||
|
if (envelopeId is null)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "{Message}", ex.Message);
|
_logger.LogError("Envelope Id clam is not found in envelope-receiver-read-only creation process. Create DTO is:\n {dto}", JsonConvert.SerializeObject(createDto));
|
||||||
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
createDto.AddedWho = authReceiverMail;
|
||||||
|
createDto.EnvelopeId = envelopeId;
|
||||||
|
|
||||||
|
// create entity
|
||||||
|
var creation_res = await _erroService.CreateAsync(createDto: createDto);
|
||||||
|
|
||||||
|
if (creation_res.IsFailed)
|
||||||
|
{
|
||||||
|
_logger.LogNotice(creation_res);
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//read new entity
|
||||||
|
var read_res = await _erroService.ReadByIdAsync(creation_res.Data.Id);
|
||||||
|
if (read_res.IsFailed)
|
||||||
|
{
|
||||||
|
_logger.LogNotice(creation_res);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
|
}
|
||||||
|
|
||||||
|
var new_erro = read_res.Data;
|
||||||
|
|
||||||
|
//send email two receiver
|
||||||
|
return await _mailService.SendAsync(new_erro).ThenAsync<int, IActionResult>(SuccessAsync: async res =>
|
||||||
|
{
|
||||||
|
//TODO: implement multi-threading to history process (Task)
|
||||||
|
//TODO: remove casting after change the id type
|
||||||
|
var hist_res = await _histService.RecordAsync((int)createDto.EnvelopeId, createDto.AddedWho, EnvelopeStatus.EnvelopeShared);
|
||||||
|
if (hist_res.IsFailed)
|
||||||
|
{
|
||||||
|
_logger.LogError("Although the envelope was sent as read-only, the EnvelopeShared hisotry could not be saved. Create DTO:\n{createDto}", JsonConvert.SerializeObject(createDto));
|
||||||
|
_logger.LogNotice(hist_res.Notices);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
},
|
||||||
|
|
||||||
|
Fail: (msg, ntc) =>
|
||||||
|
{
|
||||||
|
_logger.LogNotice(ntc);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user