public async Task <ActionResult <Transaction> > PostTransaction(Transaction transaction) { CategoryValidator validator = new CategoryValidator(); if (validator.CategoryIsValid(transaction)) { _context.Transactions.Add(transaction); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTransaction", new { id = transaction.Id }, transaction)); } string errorMessage = validator.Message(transaction.Direction); return(BadRequest(new { error = errorMessage })); }
public async Task <ActionResult <Transaction> > PutTransaction(long id, Transaction transaction) { if (id != transaction.Id) { return(BadRequest()); } CategoryValidator validator = new CategoryValidator(); if (validator.CategoryIsValid(transaction)) { _context.Entry(transaction).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TransactionExists(id)) { return(NotFound()); } else { throw; } } return(transaction); } string errorMessage = validator.Message(transaction.Direction); return(BadRequest(new { error = errorMessage })); }