Ejemplo n.º 1
0
        private void InitCommands()
        {
            RemoveGame = new RelayCommand(x =>
            {
                var g      = x as Game;
                FullPrice -= g.Price;
                Games.Remove(g);
                using (var DB = new DAL.Context.SteamContext())
                {
                    DB.Account.Include("Basket").FirstOrDefault(y => y.AccountId == Infrastructure.Account.CurrentAccount.AccountId).Basket.Remove(DB.Game.FirstOrDefault(y => y.GameId == g.GameId));
                    DB.SaveChanges();
                }
            });
            Buy = new RelayCommand(x =>
            {
                using (var DB = new DAL.Context.SteamContext())
                {
                    var curAcc = DB.Account.Include("Basket").Include("Games").FirstOrDefault(y => y.AccountId == Infrastructure.Account.CurrentAccount.AccountId);

                    foreach (var item in curAcc.Basket)
                    {
                        curAcc.Games.Add(item);
                    }
                    curAcc.Basket.Clear();
                    Games.Clear();
                    FullPrice = 0;
                    DB.SaveChanges();
                }
            });
        }
Ejemplo n.º 2
0
        private void InitCommands()
        {
            RemoveGame = new RelayCommand(x =>
            {
                var g = x as Game;
                Games.Remove(g);
                using (var DB = new DAL.Context.SteamContext())
                {
                    DB.Account.Include("Wishlist").FirstOrDefault(y => y.AccountId == Infrastructure.Account.CurrentAccount.AccountId).Wishlist.Remove(DB.Game.FirstOrDefault(y => y.GameId == g.GameId));
                    DB.SaveChanges();
                }
            });
            InBasket = new RelayCommand(x =>
            {
                var Game = x as Game;
                using (var DB = new DAL.Context.SteamContext())
                {
                    var curAcc  = DB.Account.Include("Wishlist").Include("Basket").FirstOrDefault(y => y.AccountId == Infrastructure.Account.CurrentAccount.AccountId);
                    var curGame = DB.Game.FirstOrDefault(y => y.GameId == Game.GameId);

                    curAcc.Basket.Add(curGame);
                    curAcc.Wishlist.Remove(curGame);
                    Games.Remove(Game);
                    DB.SaveChanges();
                }


                //var Game = x as GameDTO;
                //if (!Account.CurrentAccount.Basket.Any(y => y.GameId == Game.GameId))
                //{
                //    Account.CurrentAccount.Basket.Add(Game);
                //    accs.CreateOrUpdate(Account.CurrentAccount);
                //}
            });
        }
Ejemplo n.º 3
0
        public BasketViewModel()
        {
            using (var DB = new DAL.Context.SteamContext())
            {
                var cur = DB.Account.Include("Basket").FirstOrDefault(y => y.AccountId == Infrastructure.Account.CurrentAccount.AccountId);
                Games.AddRange(cur.Basket);
            }

            FullPrice = Games.Sum(x => x.Price);
            InitCommands();
        }
Ejemplo n.º 4
0
        public WishlistViewModel(AccountService accs)
        {
            this.accs = accs;

            using (var DB = new DAL.Context.SteamContext())
            {
                var cur = DB.Account.Include("Wishlist").FirstOrDefault(y => y.AccountId == Infrastructure.Account.CurrentAccount.AccountId);
                Games.AddRange(cur.Wishlist);
            }


            InitCommands();
        }
Ejemplo n.º 5
0
        private void InitCommands()
        {
            InBasket = new RelayCommand(x =>
            {
                using (var DB = new DAL.Context.SteamContext())
                {
                    var curAcc = DB.Account.Include("Basket").FirstOrDefault(y => y.AccountId == Infrastructure.Account.CurrentAccount.AccountId);

                    if (!curAcc.Basket.Any(y => y.GameId == Game.GameId))
                    {
                        curAcc.Basket.Add(DB.Game.FirstOrDefault(y => y.GameId == Game.GameId));
                    }
                    DB.SaveChanges();
                }
                //if (!Account.CurrentAccount.Basket.Any(y => y.GameId == Game.GameId))
                //{
                //    Account.CurrentAccount.Basket.Add(Game);
                //    accs.CreateOrUpdate(Account.CurrentAccount);
                //}
            });
            InWishlist = new RelayCommand(x =>
            {
                using (var DB = new DAL.Context.SteamContext())
                {
                    var curAcc = DB.Account.Include("Wishlist").FirstOrDefault(y => y.AccountId == Infrastructure.Account.CurrentAccount.AccountId);

                    if (!curAcc.Wishlist.Any(y => y.GameId == Game.GameId))
                    {
                        curAcc.Wishlist.Add(DB.Game.FirstOrDefault(y => y.GameId == Game.GameId));
                    }
                    DB.SaveChanges();
                }
                //if (!Account.CurrentAccount.Wishlist.Any(y => y.GameId == Game.GameId))
                //{
                //    Account.CurrentAccount.Wishlist.Add(Game);
                //    accs.CreateOrUpdate(Account.CurrentAccount);
                //}
            });
        }