public async Task<IHttpActionResult> PutNewsFeed(int id, NewsFeed newsFeed) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != newsFeed.Id) { return BadRequest(); } db.Entry(newsFeed).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NewsFeedExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostNewsFeed(NewsFeedBinding newsFeedModel) { if (!ModelState.IsValid) { return BadRequest(ModelState); } ApplicationUser appuser = await _userManager.FindByIdAsync(User.Identity.GetUserId()); var newsFeed = new NewsFeed() { Title = newsFeedModel.Title, Body = newsFeedModel.Body, Author = appuser }; db.NewsFeeds.Add(newsFeed); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = newsFeed.Id }, newsFeed); }