public IHttpActionResult PostCustomBill(CustomBillModel customBillModel) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var customBill = new CustomBill { BillName = customBillModel.BillName, EstimatedAmount = customBillModel.EstimatedAmount, UserId = customBillModel.UserId, WebsiteUrl = customBillModel.WebsiteUrl }; db.CustomBills.Add(customBill); try { db.SaveChanges(); } catch (DbUpdateException) { if (CustomBillExists(customBill.CustomBillId)) { return Conflict(); } else { throw; } } customBillModel.CustomBillId = customBill.CustomBillId; return Ok(customBillModel); }
public IHttpActionResult PutCustomBill(int id, CustomBill customBill) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != customBill.CustomBillId) { return BadRequest(); } db.Entry(customBill).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CustomBillExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }