public async Task <IActionResult> SetAdvertisingMoney([FromBody] SetAdvertisingMoneyRequest 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 truncatedRequest = request.AdvertisingMoney.TruncateToPrecision(2); var setAdvertisingMoneyResult = await _royaleService.SetAdvertisingMoney(publisher, publisherGame, truncatedRequest); if (setAdvertisingMoneyResult.IsFailure) { return(BadRequest(setAdvertisingMoneyResult.Error)); } return(Ok()); } finally { _royaleSemaphore.Release(1); } }
public async Task <IActionResult> SetAdvertisingMoney([FromBody] SetAdvertisingMoneyRequest 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 setAdvertisingMoneyResult = await _royaleService.SetAdvertisingMoney(publisher.Value, publisherGame, request.AdvertisingMoney); if (setAdvertisingMoneyResult.IsFailure) { return(BadRequest(setAdvertisingMoneyResult.Error)); } return(Ok()); }