public IHttpActionResult PutLoan(int id, DataAccess.Loan loan) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != loan.ID) { return(BadRequest()); } db.Entry(loan).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!LoanExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetLoan(int id) { DataAccess.Loan loan = db.Loans.Find(id); if (loan == null) { return(NotFound()); } return(Ok(loan)); }
public IHttpActionResult PostLoan(DataAccess.Loan loan) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Loans.Add(loan); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = loan.ID }, loan)); }
public IHttpActionResult DeleteLoan(int id) { DataAccess.Loan loan = db.Loans.Find(id); if (loan == null) { return(NotFound()); } db.Loans.Remove(loan); db.SaveChanges(); return(Ok(loan)); }