public IActionResult Post([FromBody] Tracks track) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Tracks.Add(track); try { _context.SaveChanges(); } catch (DbUpdateException) { if (InventoryExists(track.TrackId)) { return(new StatusCodeResult(409)); } else { throw; } } return(CreatedAtRoute("GetTracks", new { id = track.TrackId }, track)); }
public IActionResult Post([FromBody] LastOneUsers user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existingUser = from u in _context.LastOneUsers where u.Username == user.Username select u; if (existingUser.Count <LastOneUsers>() > 0) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } _context.LastOneUsers.Add(user); try { _context.SaveChanges(); } catch (DbUpdateException) { if (UserExists(user.UserId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtRoute("GetUser", new { id = user.UserId }, user)); }