public async Task Filter_WhenCalled_ShouldReturnFilteredItems() { var item = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = true }; var item2 = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = true }; var item3 = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = false }; var entityRepository = new GamesRepository(_dbContext); var added = await entityRepository.Add(item); await entityRepository.Add(item2); await entityRepository.Add(item3); var found = entityRepository.Filter(x => x.Ready); found.Count().ShouldBe(2); }
public async Task Get_WhenItemExists_ShouldReturnItem() { var item = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = true }; var item2 = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = true }; var entityRepository = new GamesRepository(_dbContext); var added = await entityRepository.Add(item); await entityRepository.Add(item2); var found = entityRepository.Get(added.Id); found.Id.ShouldBe(added.Id); found.IsDeleted.ShouldBe(added.IsDeleted); found.Name.ShouldBe(added.Name); found.Ready.ShouldBe(added.Ready); }
public async System.Threading.Tasks.Task <OperationResult <MyGameReponseSingle> > GetMyGames(int pageSize, int pageNumber, bool descending) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <MyGameReponseSingle> >(() => { OperationResult <MyGameReponseSingle> result = new OperationResult <MyGameReponseSingle>(); try { result.Count = GamesRepository.Count("CreatorId = @CreatorId", new { CreatorId = CurrentUser.Id }); if (result.Count > 0) { List <MyGameReponseSingle> response = new List <MyGameReponseSingle>(); var games = GamesRepository.Search("CreatorId = @CreatorId", new { PageSize = pageSize, PageNumber = pageNumber, CreatorId = CurrentUser.Id }, descending); foreach (var game in games) { MyGameReponseSingle single = new MyGameReponseSingle(); single.Game = game; single.Playground = PlaygroundsRepository.Read(game.Playground); single.GameType = GameTypesRepository.Read(game.GameType); response.Add(single); } result.MultipleResult = response; } result.Result = true; } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public static void AddGame() { HeaderMenu.Show(); Console.WriteLine("You are at: > Games > New game"); Console.WriteLine(""); Game game = new Game(); Console.WriteLine("Input product title: "); game.Title = Console.ReadLine(); Console.Write("Input product price: "); game.Price = Convert.ToDecimal(Console.ReadLine()); GamesRepository.Insert(game); Console.WriteLine(""); Console.WriteLine("Product inserted successfully!"); Console.WriteLine(""); Console.WriteLine("Press any key to return to games main menu..."); Console.ReadKey(); //Show(); }
public async System.Threading.Tasks.Task <OperationResult <MyGameReponseSingle> > CreateMyGame(Game game) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <MyGameReponseSingle> >(() => { OperationResult <MyGameReponseSingle> result = new OperationResult <MyGameReponseSingle>(); try { game.CreatorId = CurrentUser.Id; Game newGame = GamesRepository.CreateOrUpdate(game); if (newGame.Id > 0) { newGame.CreatorId = Guid.Empty; MyGameReponseSingle single = new MyGameReponseSingle(); single.Playground = PlaygroundsRepository.Read(game.Playground); single.GameType = GameTypesRepository.Read(game.GameType); single.Game = newGame; single.Orders = EquipmentOrdersRepository.Search("GameId = @GameId", new { PageSize = 1, PageNumber = 200, GameId = game.Id }, true); result.SingleResult = single; result.Result = true; } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public HttpResponseMessage UpdateGame([FromUri] int id, [FromBody] UpdateGameRequest request) { try { var game = GamesRepository.ConsultGameById(id); if (game == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } game.Title = request.Title; game.Developer = request.Developer; game.Image = request.Image; game.Description = request.Description; game.ReleaseDate = request.ReleaseDate; game.Category = request.Category; GamesRepository.UpdateGame(id, request.Title, request.Developer, request.Image, request.Description, request.ReleaseDate, request.Category); return(Request.CreateResponse(HttpStatusCode.OK, game)); } catch (Exception e) { Console.WriteLine($"An Exception has been caught: {e.Message}"); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public async System.Threading.Tasks.Task <OperationResult <EquipmentOrder> > ReadEquipmentOrder(int Id) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <EquipmentOrder> >(() => { OperationResult <EquipmentOrder> result = new OperationResult <EquipmentOrder>(); try { EquipmentOrder order = EquipmentOrdersRepository.Read(Id); if (order != null) { Game game = GamesRepository.Read(order.GameId); if (game != null) { if (game.CreatorId == CurrentUser.Id || IsInCompany(game.CompanyId) || UserStore.IsInRole(CurrentUser, RoleNames.Admin)) { result.SingleResult = order; result.Result = true; } } } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public async System.Threading.Tasks.Task <OperationResult <EquipmentOrder> > GetEquipmentOrders(int gameId, int pageSize, int pageNumber, bool descending) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <EquipmentOrder> >(() => { OperationResult <EquipmentOrder> result = new OperationResult <EquipmentOrder>(); try { Game game = GamesRepository.Read(gameId); if (game != null) { if (game.CreatorId == CurrentUser.Id || IsInCompany(game.CompanyId) || UserStore.IsInRole(CurrentUser, RoleNames.Admin)) { result.Count = EquipmentOrdersRepository.Count("GameId = @GameId", new { GameId = game.Id }); if (result.Count > 0) { result.MultipleResult = EquipmentOrdersRepository.Search("GameId = @GameId", new { PageSize = pageSize, PageNumber = pageNumber, GameId = game.Id }, descending); } result.Result = true; } } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public async Task Get_WhenItemDoesNotExist_ShouldReturnNull() { var item = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = true }; var item2 = new Game() { Name = "example", CreatedBy = "user", IsDeleted = false, Ready = true }; var entityRepository = new GamesRepository(_dbContext); var added = await entityRepository.Add(item); await entityRepository.Add(item2); var result = entityRepository.Get("not existing id"); result.ShouldBeNull(); }
public static void ListGames() { HeaderMenu.Show(); Console.WriteLine("You are at: > Games > List all games"); Console.WriteLine(""); Console.WriteLine($"╔{new string('═', 109)}╗"); Console.WriteLine($"║ GAMES LIST{new string(' ', 98)}║"); Console.WriteLine($"╠═{new string('═', 3)}═╦═{new string('═', 20)}═╦═{new string('═', 40)}═╦═{new string('═', 10)}═╦═{new string('═', 10)}═╦═{new string('═', 9)}═╣"); Console.WriteLine($"║ {"ID",-3} ║ {"Category",-20} ║ {"Title",-40} ║ {"Console",-10} ║ {"Stock qty.",-10} ║ {"Price",-9} ║"); Console.WriteLine($"╠═{new string('═', 3)}═╬═{new string('═', 20)}═╬═{new string('═', 40)}═╬═{new string('═', 10)}═╬═{new string('═', 10)}═╬═{new string('═', 9)}═╣"); foreach (var game in GamesRepository.List()) { Console.WriteLine($"║ {game.ID,3} ║ {game.Category,-20} ║ {game.Title,-40} ║ {game.Console,-10} ║ {game.StockQuantity,10} ║ {game.Price,9:N2} ║"); } Console.WriteLine($"╚═{new string('═', 3)}═╩═{new string('═', 20)}═╩═{new string('═', 40)}═╩═{new string('═', 10)}═╩═{new string('═', 10)}═╩═{new string('═', 9)}═╝"); Console.WriteLine(""); Console.WriteLine("Press any key to return to games main menu..."); Console.ReadKey(); //Show(); }
public TournamentsController(CvarcDbContext context, TournamentGenerator tournamentGenerator, GamesRepository gamesRepository) { this.context = context; this.tournamentGenerator = tournamentGenerator; this.gamesRepository = gamesRepository; }
public HttpResponseMessage StartGame(string sessionKey, int gameId) { var response = this.PerformOperation(() => { var userId = UsersRepository.LoginUser(sessionKey); GamesRepository.StartGame(userId, gameId); }); return(response); }
public HttpResponseMessage JoinGame(string sessionKey, [FromBody] JoinGameModel gameModel) { var response = this.PerformOperation(() => { var userId = UsersRepository.LoginUser(sessionKey); GamesRepository.JoinGame(userId, gameModel); }); return(response); }
public void AddGetGameTest() { GamesRepository repository = new GamesRepository(MainTest.ConnectionString); string name = MainTest.GetRandomName(10); repository.AddGame(new Game(name)); _gamesList.Add(name); Assert.AreEqual(name, repository.GetGame(name).Name); }
public ActionResult Index(Games game) { using (var db = new SimonOMarcusEntities()) { var repos = new GamesRepository(); repos.AddGame(game.GameId, game.HomeScore, game.AwayScore, game.HomeTeam, game.AwayTeam); ViewBag.Mess = "You have registered a game!"; } return(View(game)); }
public IActionResult Index() { var model = new GamesViewModel(); var gamesRepo = new GamesRepository(_context); model.Games = gamesRepo.GetAllPublicGames(); model.GameURL = _config.Value.GameURL; return(View(model)); }
public HttpResponseMessage GetMyActiveGames(string sessionKey) { var response = this.PerformOperation(() => { var userId = UsersRepository.LoginUser(sessionKey); var activeGames = GamesRepository.GetActiveGames(userId); return(activeGames); }); return(response); }
public HttpResponseMessage GetAllGameGuesses(string sessionKey, int gameId) { var response = this.PerformOperation(() => { var userId = UsersRepository.LoginUser(sessionKey); var gameState = GamesRepository.GetGameState(gameId, userId); return(gameState); }); return(response); }
private static List <Game> GetOpenGames() { var gamesRepository = new GamesRepository(); var allGames = gamesRepository.Get().ToList(); WriteLine(string.Format("Got {0} games from database", allGames.Count)); var openGames = allGames.OrderBy(game => game.Date).Where(game => game.Date.Subtract(TimeSpan.FromMinutes(30)) > DateTime.UtcNow).ToList(); WriteLine(string.Format("{0} games are still open", openGames.Count)); return(openGames); }
public void CleanUp() { if (_gamesList.Count == 0) { return; } GamesRepository repository = new GamesRepository(MainTest.ConnectionString); foreach (string gameName in _gamesList) { repository.DeleteGame(gameName); } }
public HttpResponseMessage ObtainGames() { try { var listGames = GamesRepository.ConsultGames(); return(Request.CreateResponse(HttpStatusCode.OK, listGames)); } catch (Exception e) { Console.WriteLine($"An Exception has been caught: {e.Message}"); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public HttpResponseMessage CreateGame([FromBody] GameRequest request) { try { var game = GamesRepository.InsertGame(request.Title, request.Developer, request.Image, request.Description, request.ReleaseDate, request.Category); return(Request.CreateResponse(HttpStatusCode.OK, game)); } catch (Exception e) { Console.WriteLine($"An Exception has been caught: {e.Message}"); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public HttpResponseMessage DeleteGame(int id) { try { GamesRepository.DeleteGame(id); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception e) { Console.WriteLine($"An Exception has been caught: {e.Message}"); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
private void btnLoadDeck_Click(object sender, EventArgs e) { listDeckList.Items.Clear(); GamesRepository proxy = new GamesRepository(); Game mygame = proxy.Games[GameIndex]; openFileDialog1.Filter = "OCTGN deck files (*.o8d) | *.o8d"; openFileDialog1.InitialDirectory = mygame != null ? mygame.DefaultDecksPath : null; if (openFileDialog1.ShowDialog() == DialogResult.OK) { Deck newDeck; try { newDeck = Deck.Load(openFileDialog1.FileName, proxy); } catch (DeckException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } catch (Exception ex) { MessageBox.Show("OCTGN couldn't load the deck.\r\nDetails:\r\n\r\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } for (int I = 0; I < newDeck.Sections[0].Cards.Count; I++) { ListViewItem card = new ListViewItem(); card.Text = newDeck.Sections[0].Cards[I].Card.Name; Set cardSet = newDeck.Sections[0].Cards[I].Card.Set; card.SubItems.Add(cardSet.Name); card.SubItems.Add(newDeck.Sections[0].Cards[I].Quantity.ToString()); card.SubItems.Add(newDeck.Sections[0].Cards[I].Card.Id.ToString()); listDeckList.Items.Add(card); } if (checkBox1.Checked == true) { for (int I = 0; I < newDeck.Sections[1].Cards.Count; I++) { ListViewItem card = new ListViewItem(); card.Text = newDeck.Sections[1].Cards[I].Card.Name; Set cardSet = newDeck.Sections[1].Cards[I].Card.Set; card.SubItems.Add(cardSet.Name); card.SubItems.Add(newDeck.Sections[1].Cards[I].Quantity.ToString()); card.SubItems.Add(newDeck.Sections[1].Cards[I].Card.Id.ToString()); listDeckList.Items.Add(card); } } } }
public async Task CreatesGame() { using (var context = new ApplicationDbContext(_options)) { var gamesRepository = new GamesRepository(context); await gamesRepository.Create(new Game { Id = 1 }); } using (var context = new ApplicationDbContext(_options)) { Assert.Equal(1, context.Games.Count()); Assert.Equal(1, context.Games.Single().Id); } }
protected override async Task Perform(object?parameter) { if (!(parameter is SaveGameArguments args)) { return; } args.EditGameViewModel.Status = EditGameViewModel.ViewStatus.DownloadingScreenshots; try { await using var database = Application.Current.Database(); var game = args.GameId == 0 ? new GameCopy() : GamesRepository.LoadGame(database, args.GameId); if (game.IsNew) { database.Add(game); } UpdateGame(game, args.EditGameViewModel); await PersistGame(database); var destinationDirectory = BuildGamePath(game); var screenshots = await DownloadScreenshots( Path.Combine(destinationDirectory, "screenshots"), args.EditGameViewModel.GameScreenshots, args.Progress ); var cover = await DownloadCoverArt(destinationDirectory, args.EditGameViewModel.GameCoverImage); game.CoverImage = cover; game.Screenshots = screenshots.Distinct().ToList(); await PersistGame(database); args.EditGameViewModel.Status = EditGameViewModel.ViewStatus.Idle; } catch (Exception e) { args.EditGameViewModel.CurrentException = e; args.EditGameViewModel.Status = EditGameViewModel.ViewStatus.Error; } }
private static void ImportGames(string[] pgnFiles, string scanPath) { Console.WriteLine("Initialising repo and cache..."); IGamesRepository repo = new GamesRepository(DbContext); Console.WriteLine($"Beginning import of {pgnFiles.Length} PGN files at: {DateTime.Now}"); var fileCount = 0; pgnFiles.ToList().ForEach(file => { fileCount++; try { Console.WriteLine($"File #{fileCount}/{pgnFiles.Length} : {file}"); var pgnGames = PgnGame.ReadAllGamesFromFile(file).ToArray(); Console.WriteLine($"Checking {pgnGames.Count()} games for new entries..."); var sw = Stopwatch.StartNew(); var createdCount = repo.AddImportBatch(pgnGames); sw.Stop(); Console.WriteLine( $" File complete, {createdCount} new games added to DB (file contained {pgnGames.Count() - createdCount} duplicates) , DB Total Games: {repo.TotalGames}"); Console.WriteLine( $" time taken: {sw.Elapsed}, games created per second: {createdCount/sw.Elapsed.Seconds}"); Archiver.ArchiveImportedFile(file, scanPath); } catch (Exception e) { Console.WriteLine($"ERROR: Importing file: {file}"); Console.WriteLine(e); var failPath = Archiver.ArchiveFailedFile(file, scanPath); Console.WriteLine($"Fail archived at: {failPath}"); if (e is SqlException) { throw; } } }); }
public async System.Threading.Tasks.Task <OperationResult <Game> > UpdateGame(Game game) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <Game> >(() => { OperationResult <Game> result = new OperationResult <Game>(); try { if (IsInCompany(game.CompanyId) || game.CreatorId == CurrentUser.Id || UserStore.IsInRole(CurrentUser, RoleNames.Admin)) { result.Result = GamesRepository.Update(game); } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public HttpResponseMessage ObtainGameByCategory(string category) { try { var game = GamesRepository.ConsultGameByCategory(category); if (game == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK, game)); } catch (Exception e) { Console.WriteLine($"An Exception has been caught: {e.Message}"); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
private void listDeckList_Click(object sender, EventArgs e) { // Selected Card Image GamesRepository proxy = new GamesRepository(); Game mygame = proxy.Games[GameIndex]; Guid card = Guid.Empty; string guid = listDeckList.Items[listDeckList.SelectedItems[0].Index].SubItems[3].Text; Guid.TryParse(guid, out card); try { BitmapImage img = new BitmapImage(); System.Windows.Controls.Image CardImage = new System.Windows.Controls.Image(); mtgPicture1.Image = SourceConvert.BitmapFromUri(img != null ? CardModel.GetPictureUri(mygame, mygame.GetCardById(card).Set.Id, mygame.GetCardById(card).ImageUri) : mygame.GetCardBackUri()); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void OnLoad(GamesRepository games) { // I'm showing a message box, but don't do this, unless it's for updates or something...but don't do it every time as it pisses people off. MessageBox.Show("Hello!"); }