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