// PUT api/Beneficiary/5 public HttpResponseMessage Putbeneficiary(short id, beneficiary beneficiary) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != beneficiary.beneficiaryid) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.Entry(beneficiary).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
// GET api/Beneficiary/5 public beneficiary Getbeneficiary(short id) { beneficiary beneficiary = db.beneficiaries.Find(id); if (beneficiary == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } return(beneficiary); }
// POST api/Beneficiary public HttpResponseMessage Postbeneficiary(beneficiary beneficiary) { if (ModelState.IsValid) { db.beneficiaries.Add(beneficiary); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, beneficiary); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = beneficiary.beneficiaryid })); return(response); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public IHttpActionResult AddBeneficiary(BeneficiaryDto beneficiaryDto) { beneficiary addBeneficiary = new beneficiary { name = beneficiaryDto.name, nickname = beneficiaryDto.nickName, accountnumber = beneficiaryDto.accountNumber, ifsccode = beneficiaryDto.ifscCode, maxamount = beneficiaryDto.maxAmount, maxtransactions = beneficiaryDto.maxTransactions, address = beneficiaryDto.address, usersaccountnumber = beneficiaryDto.usersAccountNumber }; entity.beneficiaries.Add(addBeneficiary); entity.SaveChanges(); return(Ok(addBeneficiary)); }
// DELETE api/Beneficiary/5 public HttpResponseMessage Deletebeneficiary(short id) { beneficiary beneficiary = db.beneficiaries.Find(id); if (beneficiary == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } db.beneficiaries.Remove(beneficiary); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK, beneficiary)); }