public bool UpdateLobby(LobbyUpdateDto lobby, int lobbyId, int userId) { try { var existingLobby = Repository.Find(lobbyId); if (existingLobby == null) { Logger.LogWarning(LoggingEvents.CustomServiceEvents.LobbyUpdateEntryNotFound, "Lobby with id = {ID} was not found", lobbyId); return(false); } if (existingLobby.HostId != userId) { return(false); } Repository.Update(Mapper.Map(lobby, existingLobby)); Repository.SaveChanges(); _eventBus.Publish(new UpdateLobbyEvent() { UpdatedLobbyId = lobbyId, UpdatedLobby = Mapper.Map <LobbyDto>(existingLobby) }); return(true); } catch (Exception e) { Logger.LogError(LoggingEvents.CustomServiceEvents.LobbyUpdateError, e, "Error updating lobby with id = {ID}", lobbyId); return(false); } }
public IActionResult UpdateLobby(int id, [FromBody] LobbyUpdateDto lobby) { if (ModelState.IsValid) { try { var userId = _authorizationService.GetUserId(User); if (_lobbyService.UpdateLobby(lobby, id, userId)) { return(NoContent()); } } catch { } return(Unauthorized()); } return(BadRequest()); }