public static async Task <HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestMessage req, [OrchestrationClient] DurableOrchestrationClient starter, ILogger log) { log.LogInformation($"LetterReceiver --> Letter received!"); string jsonContent = await req.Content.ReadAsStringAsync(); string instanceId = null; LetterDto letter = null; try { letter = JsonConvert.DeserializeObject <LetterDto>(jsonContent); instanceId = await starter.StartNewAsync(Constants.LetterManagerOrchestratorFunction, letter); log.LogInformation($"Letter received - started orchestration with ID = '{instanceId}'."); } catch (Exception ex) { log.LogError("Error during letter received operation", ex); } return(starter.CreateCheckStatusResponse(req, instanceId)); }
public PdfSettingDto PreparePdfSetting(LetterDto letter, DepartmentDto department, List <FamilyAddressDto> addresses, PaymentDto transaction, LetterFieldsDto fields) { PdfSettingDto setting = letter?.PDFSettingID == null ? department.PdfSettings : letter.PdfSettings; if (string.IsNullOrEmpty(letter.PDFLetterText)) { throw new Exception("Letter doesn't contain pdf text"); } setting.BodyText = letter.PDFLetterText; setting.Date = DateTime.Now; MapAddressesForPdfSetting(setting, addresses.FirstOrDefault(r => r.AddressId == transaction.AddressId)); setting.Label = fields.Label; return(setting); }
/// <summary> /// CreatePdf /// </summary> /// <param name="dto"></param> /// <returns></returns> public byte[] PdfDoc(BatchLetterDto dto, bool isBase64Encode = true, string currency = "$") { LetterDto letter = null; DepartmentDto department = null; var transaction = _transactionService.GetPaymentById(dto.TransactionId); if (dto.LetterId != null) { transaction.LetterId = (short)dto.LetterId; } if (transaction.LetterId != null) { letter = _letterService.GetLetterById(transaction.LetterId.Value); } if (letter == null) { throw new Exception("Transaction don't contain letter"); } LetterFieldsDto fields = _letterService.GetLetterFields(dto.TransactionId, currency: currency); if (!string.IsNullOrEmpty(letter.PDFLetterText)) { letter.PDFLetterText = _templatesProvider.ReplaceFieldsTemplate(letter.PDFLetterText, fields); } if (letter.PDFSettingID == null) { department = _departmentService.GetDepartment(transaction.DepartmentId); } var addresses = _addressService.GetAddressesByFamilyId(transaction.FamilyId); PdfSettingDto setting = PreparePdfSetting(letter, department, addresses, transaction, fields); var country = _settingsProvider.GetSetting(Settings.DefaultCountry).Value; var response = _pdfTemplate.GetPdfFromTamplate(setting, country, fields); if (isBase64Encode) { return(EncodeBase64(response)); } return(response); }
public static async Task <ChildDto> RetrieveChild([ActivityTrigger] LetterDto letter, [Table(TableNames.ChildrenTable, "Children", Connection = "StorageAccount")] CloudTable childTable, ILogger log) { log.LogInformation($"[START ACTIVITY] --> {Constants.RetrieveChildActivityFunction} for childId={letter.ChildId}"); ChildDto child = null; try { var childRow = await childTable.GetChildByIdAsync(letter.ChildId); if (childRow == null) { childRow = new ChildRow(letter.ChildId); childRow.FirstName = letter.ChildFirstName; childRow.LastName = letter.ChildLastName; childRow.Goodness = 10; if (!await childTable.InsertAsync(childRow)) { childRow = null; } } if (childRow != null) { child = childRow.ToChildDto(); child.CurrentLetter = letter; } } catch (Exception ex) { log.LogError(ex, $"Error during retriving child"); return(null); } return(child); }