public async Task<EventViewModel> Post(EventViewModel item) { if (!ModelState.IsValid) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } item.Id = DataProvider.Calendars.Last().Id + 1; DataProvider.Calendars.Add(item); return item; }
public void Put(int id, EventViewModel item) { if (!ModelState.IsValid) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } item.Id = id; var ev = DataProvider.Calendars.FirstOrDefault(o => o.Id == id); if (ev == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } DataProvider.Calendars.Remove(ev); DataProvider.Calendars.Add(item); }