protected override async Task HandleCore(SubmitCommitmentCommand message) { var validationResult = _validator.Validate(message); if (!validationResult.IsValid()) { throw new InvalidRequestException(validationResult.ValidationDictionary); } var commitment = await _commitmentApi.GetEmployerCommitment(message.EmployerAccountId, message.CommitmentId); if (commitment.EmployerAccountId != message.EmployerAccountId) { throw new InvalidRequestException(new Dictionary <string, string> { { "Commitment", "This commitment does not belong to this Employer Account " } }); } var submission = new CommitmentSubmission { Action = message.LastAction, LastUpdatedByInfo = new LastUpdateInfo { Name = message.UserDisplayName, EmailAddress = message.UserEmailAddress }, UserId = message.UserId, Message = message.Message }; if (message.LastAction != LastAction.Approve) { await _commitmentApi.PatchEmployerCommitment(message.EmployerAccountId, message.CommitmentId, submission); } else { await _commitmentApi.ApproveCohort(message.EmployerAccountId, message.CommitmentId, submission); } if (_configuration.CommitmentNotification.SendEmail && message.LastAction != LastAction.None) { await SendNotification(commitment, message); } _logger.Info("Submit commitment"); }
public async Task PatchCommitment(long accountId, long commitmentId, CommitmentSubmission submission) { _logger.Trace($"Updating latest action to {submission.Action} for commitment {commitmentId} for employer account {accountId}", accountId: accountId, commitmentId: commitmentId); await _mediator.SendAsync(new UpdateCommitmentAgreementCommand { Caller = new Caller { CallerType = CallerType.Employer, Id = accountId }, CommitmentId = commitmentId, LatestAction = (LastAction)submission.Action, LastUpdatedByName = submission.LastUpdatedByInfo.Name, LastUpdatedByEmail = submission.LastUpdatedByInfo.EmailAddress, UserId = submission.UserId, Message = submission.Message }); _logger.Info($"Updated latest action to {submission.Action} for commitment {commitmentId} for employer account {accountId}", accountId: accountId, commitmentId: commitmentId); }
public async Task ApproveCohort(long providerId, long commitmentId, CommitmentSubmission submission) { _logger.Trace($"Approving commitment {commitmentId} for provider {providerId}", providerId: providerId, commitmentId: commitmentId); await _mediator.SendAsync(new ProviderApproveCohortCommand { Caller = new Caller { CallerType = CallerType.Provider, Id = providerId }, CommitmentId = commitmentId, LastUpdatedByName = submission.LastUpdatedByInfo.Name, LastUpdatedByEmail = submission.LastUpdatedByInfo.EmailAddress, UserId = submission.UserId, Message = submission.Message }); _logger.Info($"Approved commitment {commitmentId} for provider {providerId}", providerId: providerId, commitmentId: commitmentId); }
protected override async Task Handle(SubmitCommitmentCommand message, CancellationToken cancellationToken) { var validationResult = _validator.Validate(message); if (!validationResult.IsValid) { throw new InvalidRequestException(validationResult.Errors); } var commitment = await _commitmentsApi.GetProviderCommitment(message.ProviderId, message.CommitmentId); if (commitment.ProviderId != message.ProviderId) { throw new InvalidRequestException(new Dictionary <string, string> { { "Commitment", "This commitment does not belong to this Provider" } }); } var submission = new CommitmentSubmission { Action = message.LastAction, LastUpdatedByInfo = new LastUpdateInfo { Name = message?.UserDisplayName ?? "", EmailAddress = message?.UserEmailAddress ?? "" }, Message = message.Message, UserId = message.UserId }; if (message.LastAction != LastAction.Approve) { await _commitmentsApi.PatchProviderCommitment(message.ProviderId, message.CommitmentId, submission); } else { await _commitmentsApi.ApproveCohort(message.ProviderId, message.CommitmentId, submission); } }
public async Task <IHttpActionResult> PatchCommitment(long accountId, long commitmentId, [FromBody] CommitmentSubmission values) { await _employerOrchestrator.PatchCommitment(accountId, commitmentId, values); return(StatusCode(HttpStatusCode.NoContent)); }
public async Task PatchEmployerCommitment(long employerAccountId, long commitmentId, CommitmentSubmission submission) { var url = $"{_configuration.BaseUrl}api/employer/{employerAccountId}/commitments/{commitmentId}"; await _commitmentHelper.PatchCommitment(url, submission); }
public async Task PatchCommitment(string url, CommitmentSubmission submision) { var data = JsonConvert.SerializeObject(submision); await PatchAsync(url, data); }
public IHttpActionResult ApproveCohort(long accountId, long commitmentId, [FromBody] CommitmentSubmission values) { throw new InvalidOperationException(); }
public async Task PatchProviderCommitment(long providerId, long commitmentId, CommitmentSubmission submission) { var url = $"{_configuration.BaseUrl}api/provider/{providerId}/commitments/{commitmentId}"; await _commitmentHelper.PatchCommitment(url, submission); }
public async Task <IHttpActionResult> PatchCommitment(long providerId, long commitmentId, [FromBody] CommitmentSubmission submission) { await _providerOrchestrator.PatchCommitment(providerId, commitmentId, submission); return(StatusCode(HttpStatusCode.NoContent)); }