private async Task <CreateGameTableResultModel> ValidateAndCreate(CreateGameTableModel createGameTableModel) { var result = new CreateGameTableResultModel(); try { var newGameTable = Activator.CreateInstance <GameTable>(); newGameTable.Name = createGameTableModel.Name; newGameTable.Description = createGameTableModel.Description ?? string.Empty; newGameTable.Owner = CurrentUser ?? throw new Exception("This should not happen"); await _databaseContext.AddAsync(newGameTable); await _databaseContext.SaveChangesAsync(); result.WasSuccessful = true; } catch (Exception ex) { result.Errors = new string[] { ex.Message }; result.WasSuccessful = false; } return(result); }
public async Task <CreateGameTableResultModel> Post([FromBody] CreateGameTableModel createGameTableModel) { return(await ValidateAndCreate(createGameTableModel)); }