public PhoneCall Create(PhoneCall phoneCall) { if (phoneCall == null) { throw new ArgumentNullException("phoneCall"); } phoneCall.Id = _nextId++; _phoneCalls.Add(phoneCall); return phoneCall; }
public int Update(PhoneCall phoneCall) { if (phoneCall == null) { throw new ArgumentNullException("phoneCall"); } int index = _phoneCalls.FindIndex(e => e.Id == phoneCall.Id); if (index == -1) { return 0; } _phoneCalls.RemoveAt(index); _phoneCalls.Add(phoneCall); return 1; }
// POST /api/PhoneCall public HttpResponseMessage Post(PhoneCall phoneCall) { if (ModelState.IsValid) { try { phoneCall = _phoneCallRepository.Create(phoneCall); var response = Request.CreateResponse<CrudResult>(HttpStatusCode.Created, new CrudResult(CrudStatusCode.Success, 1, new List<PhoneCall> { phoneCall })); string uri = Url.Link("DefaultApi", new { Id = phoneCall.Id }); response.Headers.Location = new Uri(uri); return response; } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.NotModified, ex.Message); } } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }