public async Task <IActionResult> SellGame([FromBody] SellRoyaleGameRequest request) { var currentUserResult = await GetCurrentUser(); if (currentUserResult.IsFailure) { return(BadRequest(currentUserResult.Error)); } var currentUser = currentUserResult.Value; RoyalePublisher?publisher = await _royaleService.GetPublisher(request.PublisherID); if (publisher is null) { return(NotFound()); } if (!publisher.User.Equals(currentUser)) { return(Forbid()); } await _royaleSemaphore.WaitAsync(); try { var publisherGame = publisher.PublisherGames.SingleOrDefault(x => x.MasterGame.MasterGame.MasterGameID == request.MasterGameID); if (publisherGame is null) { return(BadRequest()); } var sellResult = await _royaleService.SellGame(publisher, publisherGame); if (sellResult.IsFailure) { return(BadRequest(sellResult.Error)); } return(Ok()); } finally { _royaleSemaphore.Release(1); } }
public async Task <IActionResult> SellGame([FromBody] SellRoyaleGameRequest request) { var currentUser = await _userManager.FindByNameAsync(User.Identity.Name); if (currentUser is null) { return(BadRequest()); } Maybe <RoyalePublisher> publisher = await _royaleService.GetPublisher(request.PublisherID); if (publisher.HasNoValue) { return(NotFound()); } if (!publisher.Value.User.Equals(currentUser)) { return(Forbid()); } var publisherGame = publisher.Value.PublisherGames.SingleOrDefault(x => x.MasterGame.MasterGame.MasterGameID == request.MasterGameID); if (publisherGame is null) { return(BadRequest()); } var sellResult = await _royaleService.SellGame(publisher.Value, publisherGame); if (sellResult.IsFailure) { return(BadRequest(sellResult.Error)); } return(Ok()); }