public async Task <IActionResult> PostAsync([FromForm] ExpenseAuthorizationRequest request, [FromForm] IFormFileCollection files) { // By annotating the controller with ApiControllerAttribute, // the ModelStateInvalidFilter will automatically check ModelState.IsValid // see https://docs.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-3.1#automatic-http-400-responses try { var command = new Features.ExpenseAuthorization.CreateCommand(request, files); var response = await _mediator.Send(command); if (response.Exception != null) { return(GetProblemResult(response.Exception)); } return(Ok(new ExpenseAuthorizationResponse { Id = response.Id })); } catch (Exception e) { return(GetProblemResult(e)); } }
private string FormatContactInfo(ExpenseAuthorizationRequest source) { StringBuilder buffer = new StringBuilder(); if (!string.IsNullOrEmpty(source.AuthName)) { buffer.Append("Name: "); buffer.Append(source.AuthName); } if (!string.IsNullOrEmpty(source.AuthTelephone)) { if (buffer.Length != 0) { buffer.Append('\n'); } buffer.Append("Tel: "); buffer.Append(source.AuthTelephone); } if (!string.IsNullOrEmpty(source.AuthEmail)) { if (buffer.Length != 0) { buffer.Append('\n'); } buffer.Append("Email: "); buffer.Append(source.AuthEmail); } return(buffer.ToString()); }
public CreateCommand(ExpenseAuthorizationRequest request, IEnumerable <IFormFile> files) { Request = request ?? throw new ArgumentNullException(nameof(request)); if (files != null) { Files = new List <IFormFile>(files); } }
public void ExpenditureNotToExceed_rounds_up() { ExpenseAuthorizationRequest sut = new ExpenseAuthorizationRequest(); sut.ExpenditureNotToExceed = _fixture.Create <int>() + 0.01m; var expected = Math.Ceiling(sut.ExpenditureNotToExceed); // expect to be round up Assert.Equal(expected, sut.ExpenditureNotToExceed); }
private IList <string> GetDefaultToEmailRecipients(ExpenseAuthorizationRequest request) { // if the config file does not have configured recipient, fall back to the configuration var defaultService = new DefaultEmailRecipientService(_emailOptions); var defaultList = defaultService.GetToRecipients(request); if (defaultList.Count == 0) { _logger.LogError("No default email recipients not found, sending email is probably going to fail"); } return(defaultList); }
public IDictionary <string, string> Map( ExpenseAuthorizationRequest source, string priority, string resourceCategory, string currentStatus ) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (priority == null) { throw new ArgumentNullException(nameof(priority)); } if (resourceCategory == null) { throw new ArgumentNullException(nameof(resourceCategory)); } if (currentStatus == null) { throw new ArgumentNullException(nameof(currentStatus)); } if (source == null) { throw new ArgumentNullException(nameof(source)); } var items = new Dictionary <string, string>(); items.Add("reportType", "resource_request"); items.Add("quantity", "1"); items.Add("priority", priority); items.Add("currentStatus", currentStatus); items.Add("resourceCategory", resourceCategory); // Expenditure Authorization items.Add("approvedTime", source.DateTime.ToString("o")); items.Add("requestorContactInfo", FormatContactInfo(source)); items.Add("resourceType", source.ResourceType); items.Add("requestNumber", source.EAFNo); items.Add("reqTrackNoState", source.EMBCTaskNo); items.Add("requestionOrg", source.RequestingOrg); items.Add("mission", FormatMission(source)); items.Add("estimatedResourceCost", FormatEstimatedResourceCost(source)); return(items); }
public async Task <CreateReportResponse> CreateReportAsync(ExpenseAuthorizationRequest expenseAuthorizationRequest) { if (expenseAuthorizationRequest == null) { throw new ArgumentNullException(nameof(expenseAuthorizationRequest)); } // login and get session cookie await LoginAsync(_options.Value); CreateReportResponse ret; // get the defaults, we could cache this in the future var resourceCategories = await GetLookupAsync(LookupType.ResourceCategory); var statuses = await GetLookupAsync(LookupType.StatusResource); var priorities = await GetLookupAsync(LookupType.PriorityResource); string resourceCategory = resourceCategories.FirstOrDefault(_ => _.Value == DefaultResourceCategory)?.Value; string currentStatus = statuses.FirstOrDefault(_ => _.Value == DefaultCurrentStatus)?.Id; string priority = priorities.FirstOrDefault(_ => _.Value == DefaultPriority)?.Id; var items = _mapper.Map(expenseAuthorizationRequest, priority, resourceCategory, currentStatus); var request = new CreaterReportRequest(items); string soapRequest = request.CreateSoapRequest(); try { CreateReportResponse response1 = new CreateReportResponse(); var soapResponse = await _client.CreateReportAsync(soapRequest); response1.LoadFromXml(soapResponse); ret = response1; } catch (ApiException exception) { throw new SoapFaultException(exception); } CreateReportResponse response = ret; return(response); }
public IList <string> GetToRecipients(ExpenseAuthorizationRequest request) { _logger.LogDebug("Getting the email address for {RequestingOrg}", request.RequestingOrg); // do not use the default to list var recipients = GetRecipients(request, _ => _.To, _ => Enumerable.Empty <string>()); if (recipients.Count != 0) { _logger.LogDebug("Found {@EmailRecipients} ", recipients); return(recipients); } _logger.LogInformation("Email recipient not found based on request, using the default email address from configuration"); // if the config file does not have configured recipient, fall back to the configuration return(GetDefaultToEmailRecipients(request)); }
private CommunityEmailRecipient GetCommunityEmailRecipient(ExpenseAuthorizationRequest request) { if (request?.RequestingOrg == null) { _logger.LogInformation("Request or RequestingOrg is null"); return(null); } IDictionary <string, CommunityEmailRecipient> recipients = GetRecipients(); var requestingOrg = request.RequestingOrg.Trim(); if (recipients.TryGetValue(requestingOrg, out var recipient)) { return(recipient); } return(null); }
private IList <string> GetRecipients(ExpenseAuthorizationRequest request, Func <CommunityEmailRecipient, string> fieldSelector, Func <EmailSettings, IEnumerable <string> > defaultRecipients) { List <string> recipients = new List <string>(); var recipient = GetCommunityEmailRecipient(request); if (recipient != null) { var field = fieldSelector(recipient); if (!string.IsNullOrEmpty(field)) { recipients.AddRange(field.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); } } var settings = _emailOptions.Value; recipients.AddRange(defaultRecipients(settings)); return(recipients); }
public async Task SendEmailAsync( ExpenseAuthorizationRequest request, CreateReportResponse response, IList <IFormFile> attachments) { ETeamSettings eteamSettings = _eteamOptions.Value; // create and apply data to the email template string content = new EmailTemplate() .Apply(request) .Apply(response, eteamSettings.Url) .Content; _logger.LogDebug("Getting the email to recipient list base on request"); var to = _recipientService.GetToRecipients(request); _logger.LogDebug("Email will be sent to {@EmailTo}", to); // Request from R. Wainwright, subject line of the email should // be [Region abbreviation + PREOC] – [A new EAF has been submitted to ETEAMS] // however, it is difficult to know the region abbreviation string subject = "A new EAF has been submitted to ETEAMS"; if (!string.IsNullOrEmpty(eteamSettings.Environment)) { subject = $"[{eteamSettings.Environment}] {subject}"; } var message = new Message(to, subject, content, attachments); message.AddCc(_recipientService.GetCcRecipients(request)); message.AddBcc(_recipientService.GetBccRecipients(request)); await _sender.SendEmailAsync(message); }
private string FormatMission(ExpenseAuthorizationRequest source) { int amountRequested = (int)Math.Ceiling(source.AmountRequested); return(source.Description + "\nAmount Requested: " + amountRequested); }
/// <summary>Gets to recipients.</summary> /// <param name="request">The request.</param> /// <returns> /// <br /> /// </returns> public IList <string> GetToRecipients(ExpenseAuthorizationRequest request) => Split(_ => _.DefaultSendTo);
public IList <string> GetBccRecipients(ExpenseAuthorizationRequest request) { var recipients = GetRecipients(request, _ => _.Bcc, _ => _.GetBcc()); return(recipients); }
/// <summary>Gets the BCC recipients.</summary> /// <param name="request">The request.</param> /// <returns> /// <br /> /// </returns> public IList <string> GetBccRecipients(ExpenseAuthorizationRequest request) => Split(_ => _.Bcc);
public EmailTemplate Apply(ExpenseAuthorizationRequest data) { Apply(data, "Request."); return(this); }
private string FormatEstimatedResourceCost(ExpenseAuthorizationRequest source) { int expenditureNotToExceed = (int)Math.Ceiling(source.ExpenditureNotToExceed); return(expenditureNotToExceed.ToString()); }