public bool PostCreditCard(CreditCard creditCard) { //if (!ModelState.IsValid) //{ //return BadRequest(ModelState); //} string decryptedCreditCardNumber = GetDecrypt(creditCard.CreditCardNumber); string decryptedCreditCardPin = GetDecrypt(creditCard.CreditCardPin); bool IsValid = db.CreditCards.Count(e => (e.CreditCardNumber == decryptedCreditCardNumber) && (e.CreditCardPin == decryptedCreditCardPin)) > 0; if (IsValid) { //Update database //send back yes } else { //send back false } // return IsValid; return IsValid; //db.CreditCards.Add(creditCard); //await db.SaveChangesAsync(); //return CreatedAtRoute("DefaultApi", new { id = creditCard.Id }, creditCard); }
public async Task<IHttpActionResult> PutCreditCard(int id, CreditCard creditCard) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != creditCard.Id) { return BadRequest(); } db.Entry(creditCard).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CreditCardExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }