public IActionResult Post([FromBody] MHUser mhuser) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existingUser = from g in _context.MHUser where g.Username == mhuser.Username select g; if (existingUser.Count <MHUser>() > 0) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } _context.MHUser.Add(mhuser); try { _context.SaveChanges(); } catch (DbUpdateException) { if (MHUserExists(mhuser.MHUserId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtRoute("GetMHUser", new { id = mhuser.MHUserId }, mhuser)); }
public IActionResult Post([FromBody] Album album) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Album.Add(album); try { _context.SaveChanges(); } catch (DbUpdateException) { if (AlbumExists(album.AlbumId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtRoute("GetAlbum", new { id = album.AlbumId }, album)); }
public IActionResult Post([FromBody] Song song) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Song.Add(song); try { _context.SaveChanges(); } catch (DbUpdateException) { if (SongExists(song.SongId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtRoute("GetSong", new { id = song.SongId }, song)); }