public IHttpActionResult CreateAnime(AnimeDto animeDto) { if (!ModelState.IsValid) { return(BadRequest()); } animeDto.DateAdded = DateTime.Now; var anime = Mapper.Map <AnimeDto, Anime>(animeDto); _context.Animes.Add(anime); _context.SaveChanges(); animeDto.Id = anime.Id; return(Created(new Uri(Request.RequestUri + "/" + animeDto.Id), animeDto)); }
public IHttpActionResult UpdateAnime(int id, AnimeDto animeDto) { if (!ModelState.IsValid) { return(BadRequest()); } var animeInDb = _context.Animes.SingleOrDefault(a => a.Id == id); if (animeInDb == null) { return(NotFound()); } animeDto.DateAdded = animeInDb.DateAdded; Mapper.Map(animeDto, animeInDb); _context.SaveChanges(); return(StatusCode(HttpStatusCode.NoContent)); }