Exemple #1
0
        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));
        }
Exemple #2
0
        public IHttpActionResult GetLoan(int id)
        {
            DataAccess.Loan loan = db.Loans.Find(id);
            if (loan == null)
            {
                return(NotFound());
            }

            return(Ok(loan));
        }
Exemple #3
0
        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));
        }
Exemple #4
0
        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));
        }