public static Result <Journal> ToTransaction(this JournalDTO dto, Guid?journalGuid = null) { return(JournalBuilder .Init() .WithTransactionId(journalGuid ?? Guid.Parse(dto.Id)) .WithDate(dto.Date) .WithTransactionLines(dto.Lines.Select(l => JournalLineBuilder .Init() .WithDebitCreditAmount(l.AmountDebit, l.AmountCredit) .WithDate(dto.Date) .WithAccountSourceId(l.AccountId) .WithAccountCode(l.AccountCode) .WithAccountName(l.AccountName) .WithDescription(l.Description))) .WithNumber(dto.Number) .WithReference(dto.Reference) .Build()); }
public Result <Journal> Reverse() { return(JournalBuilder .Init() .WithTransactionId(Guid.NewGuid()) .WithDate(Date) .WithTransactionLines(Lines .Select(l => JournalLineBuilder .Init() .WithAmount(l.Amount.Reverse()) .WithDate(l.Date) .WithAccount(l.AccountDescriptor) .WithDescription(l.Description))) .WithNumber(Number) .WithReference(Reference) .WithSource(string.Format("Reversing {0}", Id).Trim()) .Build()); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "add")] HttpRequest req, [CosmosDB( databaseName: "FreedomFriday", collectionName: "journals", ConnectionStringSetting = "freedomfridayserverless_DOCUMENTDB")] IAsyncCollector <JournalDTO> journalStore, ILogger log) { log.LogInformation("JournalHttpTrigger function processed a request."); var dto = req.Body.Deserialize <JournalDTO>(); var result = JournalBuilder .Init() .WithTransactionId(Guid.NewGuid()) .WithDate(dto.Date) .WithTransactionLines(dto.Lines.Select(l => JournalLineBuilder .Init() .WithDebitCreditAmount(l.AmountDebit, l.AmountCredit) .WithDate(dto.Date) .WithAccountSourceId(l.AccountId) .WithAccountCode(l.AccountCode) .WithAccountName(l.AccountName) .WithDescription(l.Description))) .WithNumber(dto.Number) .WithReference(dto.Reference) .WithDateUpdated(DateTime.UtcNow) .Build() .OnSuccess(journal => Result.Ok(journal.ToJournalDto())); if (result.IsFailure) { return(result.ToActionResult()); } await journalStore.AddAsync(result.Value); return(result.ToActionResult()); }
public static async Task <Result <JournalDTO> > AddJournal( [ActivityTrigger] JournalDTO dto, [CosmosDB( databaseName: "FreedomFriday", collectionName: "journals", ConnectionStringSetting = "freedomfridayserverless_DOCUMENTDB")] IAsyncCollector <JournalDTO> journalStore, ILogger log) { log.LogInformation("DurableFunctionsOrchestration_Journal function processed a request."); var result = JournalBuilder .Init() .WithTransactionId(Guid.NewGuid()) .WithDate(dto.Date) .WithTransactionLines(dto.Lines.Select(l => JournalLineBuilder .Init() .WithDebitCreditAmount(l.AmountDebit, l.AmountCredit) .WithDate(dto.Date) .WithAccountSourceId(l.AccountId) .WithAccountCode(l.AccountCode) .WithAccountName(l.AccountName) .WithDescription(l.Description))) .WithNumber(dto.Number) .WithReference(dto.Reference) .WithDateUpdated(DateTime.UtcNow) .Build() .OnSuccess(journal => Result.Ok(journal.ToJournalDto())); if (result.IsFailure) { return(result); } await journalStore.AddAsync(result.Value); return(result); }