public void Cannot_insert_ledgerTransaction_with_no_lines() { var testTransaction = this.GetTestLedgerTransactionWithNoLines(); Assert.Throws <ArgumentException>( () => _ledgerTransactionService.InsertLedgerTransaction(testTransaction)); }
public IActionResult Add([FromBody] LedgerTransactionViewModel ltvm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { // TODO: get the user creating the ledger account // get the admin creating the student // var adminId = GetCurrentUserId(); // if (adminId == null) return NotFound(new { error = "User is not authenticated." }); // var admin = _dbContext.Admins.SingleOrDefault(i => i.Id == adminId); // if (admin == null) return NotFound(new { error = $"User ID {adminId} has not been found" }); var ledgerTransaction = new LedgerTransaction { Documentation = ltvm.Documentation, Description = ltvm.Description, PostingDate = DateTime.ParseExact(ltvm.PostingDate, "dd-MM-yyyy", CultureInfo.InvariantCulture), IsEditable = ltvm.IsEditable, ChartOfAccountsId = ltvm.ChartOfAccountsId, LedgerTransactionLines = ltvm.LedgerTransactionLines.Select(line => new LedgerTransactionLine { Amount = line.Amount, IsDebit = line.IsDebit, LedgerAccountId = line.LedgerAccountId }).ToList() }; _ledgerTransactionService.InsertLedgerTransaction(ledgerTransaction); // return the newly-created ledger transaction to the client. return(new JsonResult(Mapper.Map <LedgerTransaction, LedgerTransactionViewModel>(ledgerTransaction), DefaultJsonSettings)); } catch (Exception e) { // return the error. return(BadRequest(new { Error = e.Message })); } }