public async Task <IActionResult> SignIn([FromBody] AuthenticationApiModel model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entity = await _service.GetByUserNameAsync(model); var resultModel = await _service.AuthenticateAsync(entity, model.Password, model.Remember); if (resultModel.ResultStatus == ResultStatusEnum.Failed) { return(Unauthorized()); } return(Ok(resultModel)); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public BulksignResult <EnvelopeApiModel> PrepareSendEnvelope([FromBody] FileInput[] files) { AuthenticationApiModel apiToken = ExtractApiAuthenticationToken(); BulkSignApi api = new BulkSignApi(IntegrationSettings.BulksignRestUrl); BulksignResult <EnvelopeApiModel> result = api.PrepareSendEnvelope(apiToken, files); return(result); }
public void DownloadCompletedDocuments(string envelopeId, string apiKey, string email) { log.Info($"Preparing to download documents for completed envelope '{envelopeId}' "); BulkSignApi api = new BulkSignApi(IntegrationSettings.BulksignRestUrl); AuthenticationApiModel token = new AuthenticationApiModel() { UserEmail = email, Key = apiKey }; BulksignResult <EnvelopeStatusTypeApi> envelopeStatus = api.GetEnvelopeStatus(token, envelopeId); if (envelopeStatus.IsSuccessful == false) { //it seems the envelope doesn't exist if (envelopeStatus.ErrorCode == ApiErrorCode.API_ERROR_CODE_ENVELOPE_WITH_ID_NOT_FOUND) { log.Error($"{nameof(DownloadCompletedDocuments)} , for envelopeId '{envelopeId}', GetEnvelopeStatus returned '{ApiErrorCode.API_ERROR_MESSAGE_ENVELOPE_WITH_ID_NOT_FOUND}' , envelope doesn't exists anymore"); new DbIntegration().UpdateEnvelopeStatus(envelopeId, Constants.ENVELOPE_DELETED); } else { log.Error($" {nameof(DownloadCompletedDocuments)} failed for '{envelopeId}', calling GetEnvelopeStatus failed with code : '{envelopeStatus.ErrorCode}', message : '{envelopeStatus.ErrorMessage}' "); } return; } if (envelopeStatus.Response != EnvelopeStatusTypeApi.Completed) { log.Error($" Invalid envelope status received in {nameof(DownloadCompletedDocuments)} for envelopeId '{envelopeId}', status {envelopeStatus.ToString()} "); //just update the status new DbIntegration().UpdateEnvelopeStatus(envelopeId, envelopeStatus.ToString().ToLower()); return; } BulksignResult <byte[]> result = api.DownloadEnvelopeCompletedDocuments(token, envelopeId); if (result.IsSuccessful == false) { log.Error($" {nameof(DownloadCompletedDocuments)} failed, code : {result.ErrorCode}, message : {result.ErrorMessage} "); return; } string fullPath = IntegrationSettings.CompletedEnvelopePath + @"\" + envelopeId + ".zip"; File.WriteAllBytes(fullPath, result.Response); new DbIntegration().UpdateEnvelopeCompletedDocumentPath(envelopeId, fullPath); }
public void CheckEnvelopeStatus(SentEnvelopeModel envelope) { try { log.Info($"Checking status for envelope '{envelope.Id}' "); BulkSignApi api = new BulkSignApi(IntegrationSettings.BulksignRestUrl); AuthenticationApiModel token = new AuthenticationApiModel() { UserEmail = envelope.SenderEmail, Key = envelope.ApiToken }; BulksignResult <EnvelopeStatusTypeApi> envelopeStatus = api.GetEnvelopeStatus(token, envelope.Id); if (envelopeStatus.IsSuccessful == false) { //it seems the envelope doesn't exist anymore, must have been deleted if (envelopeStatus.ErrorCode == ApiErrorCode.API_ERROR_CODE_ENVELOPE_WITH_ID_NOT_FOUND) { log.Error($"{nameof(DownloadCompletedDocuments)} , GetEnvelopeStatus returned {ApiErrorCode.API_ERROR_MESSAGE_ENVELOPE_WITH_ID_NOT_FOUND} , envelope doesn't exists"); new DbIntegration().UpdateEnvelopeStatus(envelope.Id, Constants.ENVELOPE_DELETED); } else { log.Error($" {nameof(DownloadCompletedDocuments)} failed for '{envelope.Id}', calling GetEnvelopeStatus failed with code : '{envelopeStatus.ErrorCode}', message : '{envelopeStatus.ErrorMessage}' "); } return; } //was the status changed if ((int)envelopeStatus.Response != Constants.NUMERIC_ENVELOPE_STATUS_IN_PROGRESS) { log.Info($"Updating status for envelope '{envelope.Id}', new status is '{envelopeStatus.Response.ToString()}' "); new DbIntegration().UpdateEnvelopeStatus(envelope.Id, envelopeStatus.Response.ToString()); } else { log.Info($"Status for envelope '{envelope.Id}' is not changed"); } } catch (Exception ex) { log.Error(ex); } }
public BulksignResult <SendEnvelopeResultApiModel> SendEnvelopeFromTemplate([FromBody] EnvelopeFromTemplateApiModel model) { AuthenticationApiModel apiToken = ExtractApiAuthenticationToken(); BulkSignApi api = new BulkSignApi(IntegrationSettings.BulksignRestUrl); BulksignResult <SendEnvelopeResultApiModel> result = api.SendEnvelopeFromTemplate(apiToken, model); if (result.IsSuccessful) { try { new DbIntegration().AddSentEnvelope(apiToken.UserEmail, apiToken.Key, result.Response.EnvelopeId, string.Empty); } catch (Exception ex) { log.Error(ex, $"Failed to store data about envelope '{result.Response}' "); } } return(result); }
public BulksignResult <string> DeleteEnvelope(string envelopeId) { AuthenticationApiModel apiToken = ExtractApiAuthenticationToken(); BulkSignApi api = new BulkSignApi(IntegrationSettings.BulksignRestUrl); BulksignResult <string> result = api.DeleteEnvelope(apiToken, envelopeId); if (result.IsSuccessful) { try { new DbIntegration().UpdateEnvelopeStatus(envelopeId, Constants.ENVELOPE_DELETED); } catch (Exception ex) { log.Error(ex, $"Failed to store envelope '{result.Response}'"); } } return(result); }
public BulksignResult <SendEnvelopeResultApiModel> SendEnvelope([FromBody] EnvelopeApiModel bundle) { AuthenticationApiModel apiToken = ExtractApiAuthenticationToken(); BulkSignApi api = new BulkSignApi(IntegrationSettings.BulksignRestUrl); BulksignResult <SendEnvelopeResultApiModel> result = api.SendEnvelope(apiToken, bundle); if (result.IsSuccessful) { try { string bundleConfiguration = IntegrationSettings.StoreEnvelopeConfiguration ? JsonConvert.SerializeObject(bundle) : string.Empty; new DbIntegration().AddSentEnvelope(apiToken.UserEmail, apiToken.Key, result.Response.EnvelopeId, bundleConfiguration); } catch (Exception ex) { log.Error(ex, $"Failed to store envelope '{result.Response.EnvelopeId}'"); } } return(result); }
public async Task <HeroEntity> GetByUserNameAsync(AuthenticationApiModel model) { var entity = await _userManager.FindByNameAsync(model.Login); return(entity); }