コード例 #1
0
        public async Task <IActionResult> Index()
        {
            var userId          = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var neighbor        = _context.Neighbors.Where(n => n.ApplicationUserId == userId).FirstOrDefault();
            var shopOwners      = new List <ShopOwner>();
            var shopOwnersInZip = _context.ShopOwners.Where(s => s.ZipCode == neighbor.ZipCode);
            var shopHashtags    = _context.ShopHashtags.Where(s => s.ZipCode == neighbor.ZipCode);
            var shopOwnerIds    = new List <int>();
            var hashtags        = _context.Hashtags.Where(h => h.NeighborId == neighbor.Id);

            foreach (var h in hashtags)
            {
                foreach (var s in shopHashtags)
                {
                    if (h.Text == s.Text)
                    {
                        var shopOwnerId = s.ShopOwnerId;

                        if (shopOwnerIds.Contains(shopOwnerId) == true)
                        {
                            continue;
                        }
                        else
                        {
                            shopOwnerIds.Add(shopOwnerId);
                        }
                    }
                }
            }
            foreach (var shopOwnerId in shopOwnerIds)
            {
                var shopOwner = _context.ShopOwners.Where(s => s.Id == shopOwnerId).FirstOrDefault();
                if (shopOwners.Contains(shopOwner))
                {
                    continue;
                }
                else
                {
                    shopOwners.Add(shopOwner);
                }
            }
            //var applicationDbContext = _context.ShopOwners.Include(s => s.ApplicationUser);
            ShopOwnerSubscriptionViewModel shopOwnerSubscriptionViewModel = new ShopOwnerSubscriptionViewModel();

            shopOwnerSubscriptionViewModel.ShopOwners = shopOwners;
            shopOwnerSubscriptionViewModel.Neighbor   = neighbor;
            return(View(shopOwnerSubscriptionViewModel));
        }
コード例 #2
0
        public async Task <IActionResult> Index(IEnumerable <bool> subscriptionStatus)
        {
            {
                var userId          = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                var neighbor        = _context.Neighbors.Where(n => n.ApplicationUserId == userId).FirstOrDefault();
                var shopOwners      = new List <ShopOwner>();
                var shopOwnersInZip = _context.ShopOwners.Where(s => s.ZipCode == neighbor.ZipCode);
                var shopHashtags    = _context.ShopHashtags.Where(s => s.ZipCode == neighbor.ZipCode);
                var shopOwnerIds    = new List <int>();
                var hashtags        = _context.Hashtags.Where(h => h.NeighborId == neighbor.Id);

                foreach (var h in hashtags)
                {
                    foreach (var s in shopHashtags)
                    {
                        if (h.Text == s.Text)
                        {
                            var shopOwnerId = s.ShopOwnerId;

                            if (shopOwnerIds.Contains(shopOwnerId) == true)
                            {
                                continue;
                            }
                            else
                            {
                                shopOwnerIds.Add(shopOwnerId);
                            }
                        }
                    }
                }
                foreach (var shopOwnerId in shopOwnerIds)
                {
                    var shopOwner = _context.ShopOwners.Where(s => s.Id == shopOwnerId).FirstOrDefault();
                    if (shopOwners.Contains(shopOwner))
                    {
                        continue;
                    }
                    else
                    {
                        shopOwners.Add(shopOwner);
                    }
                }
                foreach (bool s in subscriptionStatus)
                {
                    foreach (var shopOwner in shopOwners)
                    {
                        if (s == false)
                        {
                            continue;
                        }
                        else
                        {
                            Subscription subscription = new Subscription();
                            subscription.NeighborId         = neighbor.Id;
                            subscription.ShopOwnerId        = shopOwner.Id;
                            subscription.SubscriptionStatus = s;
                        }
                    }
                }



                //var applicationDbContext = _context.ShopOwners.Include(s => s.ApplicationUser);
                ShopOwnerSubscriptionViewModel shopOwnerSubscriptionViewModel = new ShopOwnerSubscriptionViewModel();
                shopOwnerSubscriptionViewModel.ShopOwners = shopOwners;
                shopOwnerSubscriptionViewModel.Neighbor   = neighbor;
                await _context.SaveChangesAsync();

                return(View("Index", "Subscriptions"));
            }
        }
コード例 #3
0
        // GET: Subscriptions
        public async Task <IActionResult> Index()
        {
            var userId             = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var neighbor           = _context.Neighbors.Where(n => n.ApplicationUserId == userId).FirstOrDefault();
            var shopOwners         = new List <ShopOwner>();
            var nonlocalShopOwners = new List <ShopOwner>();
            var shopOwnersInZip    = _context.ShopOwners.Where(s => s.ZipCode == neighbor.ZipCode);
            var zipCodeList        = await _context.ZipCodes.Where(z => z.NeighborId == neighbor.Id).ToListAsync();

            var shopHashtags         = _context.ShopHashtags.Where(s => s.ZipCode == neighbor.ZipCode);
            var allShopHashtags      = _context.ShopHashtags;
            var shopOwnerIds         = new List <int>();
            var nonlocalShopOwnerIds = new List <int?>();
            var hashtags             = _context.Hashtags.Where(h => h.NeighborId == neighbor.Id);
            var subscriptions        = await _context.Subscriptions.Where(s => s.NeighborId == neighbor.Id).ToListAsync();

            var url = $"http://www.barcodes4.me/barcode/qr/Neighbor{neighbor.Id}QRCode.png?value={neighbor.Id}";

            foreach (var h in hashtags)
            {
                //adds shopOwnerId of the shopHashtag whose Text matches one of the neighbor's Hashtags to the list of shopOwnerIds if it doesn't already exist there.
                foreach (var s in shopHashtags)
                {
                    if (h.Text == s.Text)
                    {
                        var shopOwnerId = s.ShopOwnerId;

                        if (shopOwnerIds.Contains(shopOwnerId) == true)
                        {
                            continue;
                        }
                        else
                        {
                            shopOwnerIds.Add(shopOwnerId);
                        }
                    }
                }
            }
            foreach (var shopOwnerId in shopOwnerIds)
            {
                var shopOwner = _context.ShopOwners.Where(s => s.Id == shopOwnerId).FirstOrDefault();
                if (shopOwners.Contains(shopOwner))
                {
                    continue;
                }
                else
                {
                    shopOwners.Add(shopOwner);
                }
            }
            //var subscribed = new bool();
            //foreach(var subscription in subscriptions)
            //{
            //    if (subscription.Neighbor.Id == neighbor.Id)
            //    {
            //        subscribed = true;
            //    }
            //    else
            //    {
            //        subscribed = false;
            //    }
            //}



            List <ShopOwnerSubscriptionViewModel> shopOwnerSubscriptionViewModelList = new List <ShopOwnerSubscriptionViewModel>();

            var allShopOwners = await _context.ShopOwners.ToListAsync();

            List <ShopOwner> shopOwnersInNonlocalZipCodes = new List <ShopOwner>();
            var shopOwnersList = await _context.ShopOwners.Where(s => s.ZipCode == neighbor.ZipCode).ToListAsync();

            foreach (var z in zipCodeList)
            {
                foreach (var s in allShopOwners)
                {
                    if (z.NonLocalZipCode == s.ZipCode)
                    {
                        shopOwnersInNonlocalZipCodes.Add(s);
                    }
                }
            }

            var nonlocalShopHashtags = new List <ShopHashtag>();

            foreach (var s in allShopHashtags)
            {
                foreach (var z in zipCodeList)
                {
                    if (s.ZipCode == z.NonLocalZipCode)
                    {
                        nonlocalShopHashtags.Add(s);
                    }
                }
            }

            foreach (var s in nonlocalShopHashtags)
            {
                foreach (var h in hashtags)
                {
                    if (s.Text == h.Text)
                    {
                        var nonlocalShopOwnerId = s.ShopOwnerId;
                        if (nonlocalShopOwnerIds.Contains(nonlocalShopOwnerId))
                        {
                            continue;
                        }
                        else
                        {
                            nonlocalShopOwnerIds.Add(nonlocalShopOwnerId);
                        }
                    }
                }
            }

            foreach (var i in nonlocalShopOwnerIds)
            {
                var nonlocalShopOwner = _context.ShopOwners.Where(s => s.Id == i).FirstOrDefault();
                if (nonlocalShopOwners.Contains(nonlocalShopOwner))
                {
                    continue;
                }
                else
                {
                    nonlocalShopOwners.Add(nonlocalShopOwner);
                }
            }

            ShopOwnerSubscriptionViewModel shopOwnerSubscriptionViewModel = new ShopOwnerSubscriptionViewModel();

            shopOwnerSubscriptionViewModel.Neighbor  = neighbor;
            shopOwnerSubscriptionViewModel.QRCodeURL = url;
            shopOwnerSubscriptionViewModelList.Add(shopOwnerSubscriptionViewModel);

            foreach (ShopOwner shopOwner in shopOwnersList)
            {
                ShopOwnerSubscriptionViewModel shopOwnerSubscriptionViewModelForShopOwner = new ShopOwnerSubscriptionViewModel();
                shopOwnerSubscriptionViewModelForShopOwner.ShopOwner     = shopOwner;
                shopOwnerSubscriptionViewModelForShopOwner.ShopOwners    = shopOwners;
                shopOwnerSubscriptionViewModelForShopOwner.Neighbor      = neighbor;
                shopOwnerSubscriptionViewModelForShopOwner.Subscriptions = subscriptions;
                foreach (var s in subscriptions)
                {
                    shopOwnerSubscriptionViewModelForShopOwner.Subscription = s;
                }
                shopOwnerSubscriptionViewModelForShopOwner.Subscribed   = _context.Subscriptions.Where(s => s.ShopOwnerId == shopOwner.Id && s.NeighborId == neighbor.Id).Select(s => s.SubscriptionStatus).SingleOrDefault();
                shopOwnerSubscriptionViewModelForShopOwner.ShopOwnerIds = shopOwnerIds;
                shopOwnerSubscriptionViewModelList.Add(shopOwnerSubscriptionViewModelForShopOwner);
            }

            foreach (ShopOwner nonlocalShopOwner in nonlocalShopOwners)
            {
                ShopOwnerSubscriptionViewModel shopOwnerSubscriptionViewModelForNonlocalShopOwner = new ShopOwnerSubscriptionViewModel();
                shopOwnerSubscriptionViewModelForNonlocalShopOwner.NonlocalShopOwner  = nonlocalShopOwner;
                shopOwnerSubscriptionViewModelForNonlocalShopOwner.NonlocalShopOwners = nonlocalShopOwners;
                shopOwnerSubscriptionViewModelForNonlocalShopOwner.Neighbor           = neighbor;
                shopOwnerSubscriptionViewModelForNonlocalShopOwner.Subscriptions      = subscriptions;
                foreach (var s in subscriptions)
                {
                    shopOwnerSubscriptionViewModelForNonlocalShopOwner.Subscription = s;
                }
                shopOwnerSubscriptionViewModelForNonlocalShopOwner.Subscribed           = _context.Subscriptions.Where(s => s.ShopOwnerId == nonlocalShopOwner.Id && s.NeighborId == neighbor.Id).Select(s => s.SubscriptionStatus).SingleOrDefault();
                shopOwnerSubscriptionViewModelForNonlocalShopOwner.NonlocalShopOwnerIds = nonlocalShopOwnerIds;
                shopOwnerSubscriptionViewModelList.Add(shopOwnerSubscriptionViewModelForNonlocalShopOwner);
            }
            //var applicationDbContext = _context.ShopOwners.Include(s => s.ApplicationUser);
            return(View(shopOwnerSubscriptionViewModelList));
        }