Example #1
0
 public LobbyDto CreateLobby(LobbyCreationDto newLobby, int userId)
 {
     try
     {
         var lobbyModel = Mapper.Map <Lobby>(newLobby);
         lobbyModel.HostId = userId;
         Repository.Add(lobbyModel);
         Repository.SaveChanges();
         Logger.LogInformation(LoggingEvents.CustomServiceEvents.LobbyCreateInformation, "New Lobby Created for user with id = {ID}",
                               userId);
         var lobby = Mapper.Map <LobbyDto>(Repository.Find(lobbyModel.Id));
         if (lobby != null)
         {
             _eventBus.Publish(new CreateLobbyEvent()
             {
                 NewLobby = lobby
             });
         }
         return(lobby);
     }
     catch (Exception e)
     {
         Logger.LogError(LoggingEvents.CustomServiceEvents.LobbyCreateError, e, "Error Creating lobby for user with id = {ID}",
                         userId);
         return(null);
     }
 }
 public IActionResult CreateLobby([FromBody] LobbyCreationDto newLobby)
 {
     try
     {
         if (ModelState.IsValid)
         {
             try
             {
                 var userId      = _authorizationService.GetUserId(User);
                 var lobbyResult = _lobbyService.CreateLobby(newLobby, userId);
                 if (lobbyResult != null)
                 {
                     return(CreatedAtRoute("GetLobby", new { id = lobbyResult.Id }, lobbyResult));
                 }
             }
             catch
             { }
             return(Unauthorized());
         }
         return(BadRequest());
     }
     catch
     {
         return(Unauthorized());
     }
 }