public IHttpActionResult Post(AuthorViewModel author) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Mapper.CreateMap<AuthorViewModel, Author>(); db.Authors.Add(Mapper.Map<AuthorViewModel, Author>(author)); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { Id = author.Id }, author); }
public IHttpActionResult Put(AuthorViewModel author) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Mapper.CreateMap<AuthorViewModel, Author>(); db.Entry(Mapper.Map<AuthorViewModel, Author>(author)).State = EntityState.Modified; db.SaveChanges(); return StatusCode(HttpStatusCode.NoContent); }