Пример #1
0
        public async Task <IActionResult> GetBoxOptions()
        {
            //ViewBag.StripePublishableAPIKey = APIKeys.StripePublishableAPIKey;
            //ViewBag.StripeSecretAPIKey = APIKeys.StripeSecretAPIKey;

            string IdentityId   = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            User   loggedInUser = _context.User.Where(u => u.IdentityUserId == IdentityId).SingleOrDefault();

            var beers = await GetBeersWithCompatibleStyle(loggedInUser);

            var userBeersAverageAbv = await GetUserBeersAverageAbv(loggedInUser);

            var filteredBeers = await FilterBeers(beers, userBeersAverageAbv);

            foreach (Match beer in filteredBeers)
            {
                await GetBreweryInfo(beer);

                //beer.UserId = loggedInUser.Id;
                //_context.Add(beer);
                //await _context.SaveChangesAsync();
            }

            var otherFilteredBeers = await FilterOtherBeers(beers, userBeersAverageAbv);

            foreach (Match beer in otherFilteredBeers)
            {
                await GetBreweryInfo(beer);

                //beer.UserId = loggedInUser.Id;
                //_context.Add(beer);
                //await _context.SaveChangesAsync();
            }

            var viewModel = new GetBoxOptionsViewModel();

            viewModel.PreciseMatch       = filteredBeers;
            viewModel.SomethingDifferent = otherFilteredBeers;

            List <string> preciseMatchBeerNames       = new List <string>();
            List <string> somethingDifferentBeerNames = new List <string>();

            foreach (Match beer in filteredBeers)
            {
                preciseMatchBeerNames.Add(beer.Name);
            }

            foreach (Match beer in otherFilteredBeers)
            {
                somethingDifferentBeerNames.Add(beer.Name);
            }

            viewModel.PreciseMatchBeerNames       = preciseMatchBeerNames;
            viewModel.SomethingDifferentBeerNames = somethingDifferentBeerNames;

            return(View(viewModel));
        }
        public async Task <IActionResult> BuyBeerBox(string JSONModel)
        {
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List <string>));
            var beerBox = (List <string>)ser.ReadObject(GenerateStreamFromString(JSONModel));

            var viewModel = new GetBoxOptionsViewModel();

            List <string> beerNames = new List <string>();

            foreach (string beerName in beerBox)
            {
                beerNames.Add(beerName);
            }

            viewModel.PreciseMatchBeerNames = beerNames;

            ViewBag.PaymentAmount           = amount;
            ViewBag.StripePublishableAPIKey = APIKeys.StripePublishableAPIKey;

            return(View("index", viewModel));
        }