示例#1
0
        private async Task <Unit> HandleAsync(DeleteGame request, CancellationToken cancellationToken)
        {
            var game = await _gamesRepository.Find(request.Id, cancellationToken);

            if (game is null)
            {
                throw new DomainException(Game.NOT_FOUND);
            }

            await _gamesRepository.Remove(game);

            await _unitOfWork.Save(default);
示例#2
0
        private async Task <Unit> HandleAsync(UpdateGame request, CancellationToken cancellationToken)
        {
            var game = await _gamesRepository.Find(request.Id, cancellationToken);

            if (game is null)
            {
                throw new DomainException(Game.NOT_FOUND);
            }

            game.SetName(request.Name);

            await _gamesRepository.EnsureUniqueness(game);

            await _unitOfWork.Save(default);
示例#3
0
        public static void UpdateGame()
        {
            HeaderMenu.Show();
            Console.WriteLine("You are at: > Games > Update games.");
            Console.WriteLine("");

            Console.Write("Type the ID of the game you want to update:");
            int  id   = Convert.ToInt32(Console.ReadLine());
            Game game = GamesRepository.Find(id);

            if (game != null)
            {
                Console.WriteLine($"You have selected: {game.Title}");
                Console.WriteLine("");

                Console.Write("Type the new title of the game you want to update:");
                game.Title = Console.ReadLine();
                Console.WriteLine("");

                Console.Write("Type the new price of the game you want to update:");
                game.Price = Convert.ToDecimal(Console.ReadLine());
                Console.WriteLine("");

                GamesRepository.Update(game);

                Console.WriteLine("");
                Console.WriteLine("Game updated successfully!");
                Console.WriteLine("");

                Console.WriteLine("Press any key to return.");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Error. Invalid ID.");
                Console.WriteLine("Press any key to return.");
                Console.ReadKey();
                return;
            }
        }