public IHttpActionResult PostTransaction(TransactionsModel transaction) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var dbPostTransaction = new Transaction(); dbPostTransaction.Update(transaction); dbPostTransaction.Add(transaction); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = dbPostTransaction.TransactionID }, transaction); }
public IHttpActionResult GetTransaction(int id) { Transaction dbTransaction = db.Transactions.Find(id); if (dbTransaction == null) { return NotFound(); } TransactionsModel modelTransaction = new TransactionsModel { TransactionID = dbTransaction.TransactionID, AccountID = dbTransaction.AccountID, TransactionDate = dbTransaction.TransactionDate, Amount = dbTransaction.Amount, }; return Ok(dbTransaction); }
public IHttpActionResult PutTransaction(int id, TransactionsModel transaction) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != transaction.TransactionID) { return BadRequest(); } var dbPutTransaction = db.Transactions.Find(transaction.TransactionID); dbPutTransaction.Update(transaction); db.Entry(dbPutTransaction).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TransactionExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }