public async Task<IHttpActionResult> GetContent( Guid id ) { var content = await db.Contents.FindAsync( id ); if( content == null ) { return NotFound( ); } TaskViewModel task = new TaskViewModel( content ); return Ok( task ); }
public async Task<IHttpActionResult> PostContent( TaskViewModel task ) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var content = task.ToNewContent(Request.GetUserId()); content.DateOfPublish = DateTimeOffset.Now; db.Contents.Add(content); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (ContentExists(content.Id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = task.ItemId }, task); }