Пример #1
0
        public void Reclaim(IGame game)
        {
            if (!OwnedGames.Contains(game))
            {
                throw new Exception($"game {game.Name} does not exist in OwnedGames!");
            }
            var currentUser = UserManagement.Users?.Find(user => user.ID == game.CurrentUser);

            game.CurrentUser = game.Owner;
            currentUser?.BorrowedGames.RemoveAll(borrowed => borrowed.Name == game.Name && borrowed.Owner == game.Owner);
        }
        private OwnedGames req(string idSteam, bool?jogosGratis)
        {
            var client = new RestClient($"http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=94FADF560260531F6AEDF05CD43EEC9B&steamid={idSteam}&include_appinfo=true&include_played_free_games={jogosGratis}&format=json");

            client.Timeout = -1;
            var           request  = new RestRequest(Method.GET);
            IRestResponse response = client.Execute(request);

            OwnedGames resposta = JsonConvert.DeserializeObject <OwnedGames>(response.Content);

            return(resposta);
        }
        public OwnedGames minerarPerfil(string idSteam)
        {
            var client = new RestClient($"https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=94FADF560260531F6AEDF05CD43EEC9B&steamids={idSteam}");

            client.Timeout = -1;
            var           request  = new RestRequest(Method.GET);
            IRestResponse response = client.Execute(request);

            OwnedGames resposta = JsonConvert.DeserializeObject <OwnedGames>(response.Content);

            return(resposta);
        }
Пример #4
0
        public async Task <IActionResult> Index()
        {
            var rec = await _db.OwnedGames.Include(m => m.ApplicationUser).FirstOrDefaultAsync(m => m.ApplicationUser.UserName == User.Identity.Name);

            if (rec == null)
            {
                List <Games> tempList = new List <Games>();
                rec = new OwnedGames()
                {
                    ApplicationUserId = _db.ApplicationUser.FirstOrDefault(m => m.UserName == User.Identity.Name).Id,
                    GameList          = JsonConvert.SerializeObject(tempList)
                };
            }
            var gameList = JsonConvert.DeserializeObject <IEnumerable <Games> >(rec.GameList);

            return(View(gameList));
        }
        private void buscarPerfil(string steamId = null)
        {
            if (string.IsNullOrEmpty(BoxSteamId.Text) && ItemBoxHistorico1.IsSelected)
            {
                resultadoPesquisa.Foreground = Brushes.Red;
                resultadoPesquisa.Text       = $"Preencher Steam Id";
                return;
            }
            listaJogos = _mineradorController.minerarDados(BoxSteamId.Text, RadioJogosGratis.IsChecked);

            if (listaJogos == null)
            {
                BoxSteamId.Text = "Id Invalido!";
                return;
            }

            Player player = ItemHistoricoBusca(BoxSteamId.Text);

            IdentificarSteam.Text = player.personaname;
            AtualizarTela();
        }
        private Player ItemHistoricoBusca(string steamId)
        {
            bool       repetido = false;
            OwnedGames perfil   = _mineradorController.minerarPerfil(steamId);

            foreach (var player in Players)
            {
                if (perfil.response.players[0].steamid == player.steamid)
                {
                    repetido = true;
                }
            }

            if (!repetido)
            {
                Players.Add(perfil.response.players[0]);
                BoxHistorico.Items.Add(new ComboBoxItem()
                {
                    Content = perfil.response.players[0].personaname
                });
            }

            return(perfil.response.players[0]);
        }
Пример #7
0
        public async Task <IActionResult> CheckoutPOST(int addressId, int cardId)
        {
            try
            {
                //get & calculate data needed for checkout
                var creditCard = await _db.CreditCards.FirstOrDefaultAsync(m => m.Id == cardId);

                var SA = await _db.ShippingMailingAddresses.FirstOrDefaultAsync(m => m.Id == addressId);

                var cart = await _db.Carts.Include(m => m.ApplicationUser).FirstOrDefaultAsync(m => m.ApplicationUser.UserName == User.Identity.Name);

                var ownedGameRec = await _db.OwnedGames.Include(m => m.ApplicationUser).FirstOrDefaultAsync(m => m.ApplicationUser.UserName == User.Identity.Name);

                if (ownedGameRec == null)
                {
                    List <Games> newList = new List <Games>();
                    OwnedGames   newOG   = new OwnedGames()
                    {
                        ApplicationUserId = cart.ApplicationUser.Id,
                        GameList          = JsonConvert.SerializeObject(newList)
                    };
                    _db.Add(newOG);
                    await _db.SaveChangesAsync();

                    ownedGameRec = await _db.OwnedGames.Include(m => m.ApplicationUser).FirstOrDefaultAsync(m => m.ApplicationUser.UserName == User.Identity.Name);
                }

                var ownedGamesList = JsonConvert.DeserializeObject <List <Games> >(ownedGameRec.GameList);
                if (ownedGamesList == null)
                {
                    ownedGamesList = new List <Games>();
                }

                var myCartItems     = JsonConvert.DeserializeObject <IEnumerable <Games> >(cart.MyCartItems);
                var friendCartItems = JsonConvert.DeserializeObject <Dictionary <string, IEnumerable <Games> > >(cart.FriendsCartItems);

                var    total           = SD.CalculateTaxes(SA.Province, cart.Total);
                string concatedAddress = $"{SA.StreetName} Unit {SA.HouseNumber} {SA.PostalCode} {SA.Province} {SA.City} {SA.Country}";

                //Create new order
                Orders newOrder = new Orders()
                {
                    ApplicationUserId = cart.ApplicationUser.Id,
                    MyCartItems       = cart.MyCartItems,
                    FriendsCartItems  = cart.FriendsCartItems,
                    CartTotal         = cart.Total,
                    TaxTotal          = total[0],
                    CartPlusTaxTotal  = total[1],
                    CreationDate      = DateTime.Now,
                    ShipmentAddress   = concatedAddress,
                    CreditCardHash    = creditCard.CreditCardNumberHash
                };
                _db.Add(newOrder);
                await _db.SaveChangesAsync();

                //Todo: check if game is downloadable. If it is, add it to the owned games table for the corrisponding user
                foreach (var item in myCartItems)
                {
                    if (item.isDownloadable)
                    {
                        ownedGamesList.Add(item);
                    }
                }
                ownedGameRec.GameList = JsonConvert.SerializeObject(ownedGamesList);

                foreach (var item in friendCartItems)
                {
                    var user = await _db.ApplicationUser.FirstOrDefaultAsync(m => m.UserName == item.Key);

                    var userId        = user.Id;
                    var friendGameRec = await _db.OwnedGames.Include(m => m.ApplicationUser).FirstOrDefaultAsync(m => m.ApplicationUser.Id == user.Id);

                    if (friendGameRec == null)
                    {
                        List <Games> gamesList     = new List <Games>();
                        OwnedGames   newOwnedGames = new OwnedGames()
                        {
                            ApplicationUserId = user.Id,
                            GameList          = JsonConvert.SerializeObject(gamesList)
                        };
                        _db.Add(newOwnedGames);
                        await _db.SaveChangesAsync();

                        friendGameRec = await _db.OwnedGames.Include(m => m.ApplicationUser).FirstOrDefaultAsync(m => m.ApplicationUser.Id == user.Id);
                    }
                    var gameListItems = JsonConvert.DeserializeObject <List <Games> >(friendGameRec.GameList);
                    foreach (var game in item.Value)
                    {
                        if (game.isDownloadable)
                        {
                            gameListItems.Add(game);
                        }
                    }
                    var updateOwnedGames = await _db.OwnedGames.SingleOrDefaultAsync(m => m.ApplicationUserId == user.Id);

                    updateOwnedGames.GameList = JsonConvert.SerializeObject(gameListItems);
                    await _db.SaveChangesAsync();
                }
                //Todo: Add to shipments table
                Shipments newShipment = new Shipments()
                {
                    ApplicationUserId = _db.ApplicationUser.FirstOrDefault(m => m.UserName == User.Identity.Name).Id,
                    Order             = JsonConvert.SerializeObject(newOrder),
                    StreetName        = SA.StreetName,
                    PostalCode        = SA.PostalCode,
                    Province          = SA.PostalCode,
                    City          = SA.City,
                    Country       = SA.Country,
                    isApproved    = false,
                    isProccessing = false
                };
                _db.Add(newShipment);
                _db.Remove(cart);
                await _db.SaveChangesAsync();

                return(View("CheckoutSuccess"));
            }
            catch (Exception)
            {
                ViewBag.checkoutFail = "Must add a shipping and/or credit cart to account";
                return(RedirectToAction(nameof(Index)));
            }
        }