public ActionResult CreateAjax(AuthorViewModel author) { if (ModelState.IsValid) { AutoMapper.Mapper.CreateMap<AuthorViewModel, Author>(); db.Authors.Add(AutoMapper.Mapper.Map<AuthorViewModel, Author>(author)); db.SaveChanges(); return RedirectToAction("IndexAjax"); } return View(author); }
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); }
public IHttpActionResult Put(AuthorViewModel author) { if (!ModelState.IsValid) { return BadRequest(ModelState); } AutoMapper.Mapper.CreateMap<AuthorViewModel, Author>(); db.Entry(AutoMapper.Mapper.Map<AuthorViewModel, Author>(author)).State = EntityState.Modified; db.SaveChanges(); return StatusCode(HttpStatusCode.NoContent); }
public ActionResult EditAjax(AuthorViewModel author) { if (ModelState.IsValid) { AutoMapper.Mapper.CreateMap<AuthorViewModel, Author>(); db.Entry(AutoMapper.Mapper.Map<AuthorViewModel, Author>(author)).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("IndexAjax"); } return View("FormAjax", author); }