示例#1
0
        public async Task <IActionResult> OnGetAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToPage("/Account/Login"));
            }

            Countries = new List <SelectListItem>();
            Countries.AddRange(AddressHelper.GetCountries().Select(keyValue => new SelectListItem()
            {
                Value = keyValue.Key,
                Text  = keyValue.Value
            }).OrderBy(x => x.Text));

            Provinces = new List <SelectListItem>();
            Provinces.AddRange(AddressHelper.GetProvinces().Select(keyValue => new SelectListItem()
            {
                Value = keyValue.Key,
                Text  = keyValue.Value
            }).OrderBy(x => x.Text));

            Address = new Address();

            return(Page());
        }
示例#2
0
        public async Task <IActionResult> OnGetAsync(Guid addressId)
        {
            if (addressId == null)
            {
                return(RedirectToPage("./Index"));
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToPage("/Account/Login"));
            }

            Address = await _context.Addresses.FirstOrDefaultAsync(m => m.Id == addressId);

            if (Address == null)
            {
                return(RedirectToPage("./Index"));
            }

            Countries = new List <SelectListItem>();
            Countries.AddRange(AddressHelper.GetCountries().Select(keyValue => new SelectListItem()
            {
                Value = keyValue.Key,
                Text  = keyValue.Value
            }).OrderBy(x => x.Text));

            Provinces = new List <SelectListItem>();
            Provinces.AddRange(AddressHelper.GetProvinces().Select(keyValue => new SelectListItem()
            {
                Value = keyValue.Key,
                Text  = keyValue.Value
            }).OrderBy(x => x.Text));

            return(Page());
        }
示例#3
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            comboBoxCountry.ItemsSource = AddressHelper.GetCountries();

            comboBoxPhoneType.ItemsSource = PhoneHelper.GetPhoneTypes();
        }
        public async Task <IActionResult> OnGetAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToPage("/Account/Login"));
            }

            if (!await _context.HasCartAsync(user))
            {
                return(RedirectToPage("./Index"));
            }

            var cart = await _context.GetCartAsync(user);

            CartCount = await _context.GetCartItemCount(cart);

            if (CartCount == 0)
            {
                return(RedirectToPage("./Index"));
            }

            var cartItems = _context.CartGames
                            .Include(cg => cg.Game)
                            .ThenInclude(g => g.Category)
                            .Where(cg => cg.CartId == cart.Id);

            Games = new List <Game>();
            foreach (var cartItem in cartItems)
            {
                var game = cartItem.Game;
                if (Games.Contains(game))
                {
                    continue;
                }

                Total += game.Price;
                Games.Add(game);
            }

            if (Total == 0)
            {
                return(await OnPostFreeAsync());
            }

            Countries = new List <SelectListItem>();
            Countries.AddRange(AddressHelper.GetCountries().Select(keyValue => new SelectListItem()
            {
                Value = keyValue.Key,
                Text  = keyValue.Value
            }).OrderBy(x => x.Text));

            Provinces = new List <SelectListItem>();
            Provinces.AddRange(AddressHelper.GetProvinces().Select(keyValue => new SelectListItem()
            {
                Value = keyValue.Key,
                Text  = keyValue.Value
            }).OrderBy(x => x.Text));

            Addresses = await _context.UserAddresses
                        .Include(x => x.User)
                        .Include(x => x.Address)
                        .Where(x => x.UserId == user.Id).ToListAsync();

            Payments = await _context.Payments
                       .Where(x => x.Id == user.PaymentId)
                       .ToListAsync();

            return(Page());
        }