示例#1
0
        public async Task <ProductsPageViewModel> FindProductsAsync(string sku, int pageIndex, int pageSize)
        {
            pageSize = pageSize == 0 ? _settings.DefaultPageSize : pageSize;
            PaginatedList <Product> products = await PaginatedList <Product>
                                               .FromIQueryable(_productsRepository.FindProductsAsync(sku), pageIndex, pageSize);

            if (products.Count() == 1)
            {
                //only one record found
                Product product   = products.Single();
                string  productId = product.ProductId.ToString();

                //cache a product if not in cache yet
                if (!await _productCacheRepository.IsValueCachedAsync(productId))
                {
                    await _productCacheRepository.SetValueAsync(productId, product);
                }

                //prepare prices
                if (!await _pricesCacheRepository.IsValueCachedAsync(productId))
                {
                    //prepare prices beforehand
                    ThreadPool.QueueUserWorkItem(delegate
                    {
                        CallPreparePricesApiAsync(productId);
                    });
                }
            }
            ;

            return(new ProductsPageViewModel(products));
        }
示例#2
0
        public async Task <IActionResult> Index(int?pageNumber)
        {
            var userId = (await _userManager.GetUserAsync(User)).Id;

            var userPreferences = await _db.Preferences
                                  .Include(x => x.Gender)
                                  .Include(x => x.Height)
                                  .Include(x => x.EthnicityPreferences)
                                  .ThenInclude(x => x.Ethnicity)
                                  .FirstOrDefaultAsync(x => x.UserId.ToString() == userId.ToString());



            // Filters user ethnicity preferences
            IQueryable <ApplicationUser> SearchEthnicites(List <string> keywords)
            {
                var predicate = PredicateBuilder.New <ApplicationUser>();

                foreach (string keyword in keywords)
                {
                    predicate = predicate.Or(p => p.Ethnicity.Contains(keyword));
                }
                return(_db.ApplicationUser.Where(predicate));
            }

            // If no ethnicities are selected, show all ethncities
            List <string> ethnicityPreference = new List <string>();

            foreach (var item in userPreferences.EthnicityPreferences)
            {
                ethnicityPreference.Add(item.Ethnicity.Type.ToString());
            }

            IQueryable <ApplicationUser> applicationUsersIQ;

            if (ethnicityPreference.Count() > 0)
            {
                applicationUsersIQ = SearchEthnicites(ethnicityPreference);
            }
            else
            {
                applicationUsersIQ = _db.ApplicationUser;
            }

            // Filters user gender preference
            switch (userPreferences.Gender.Type)
            {
            case "Male":
                applicationUsersIQ = applicationUsersIQ.Where(x => x.Gender.Contains("Male"));
                break;

            case "Female":
                applicationUsersIQ = applicationUsersIQ.Where(x => x.Gender.Contains("Female"));
                break;

            default:
                break;
            }

            // Filters user height preference
            if (userPreferences.Height.HeightInInches > 0)
            {
                applicationUsersIQ = applicationUsersIQ.Where(x => x.Height.HeightInInches > userPreferences.Height.HeightInInches);
            }

            // Filters user age preference
            applicationUsersIQ = applicationUsersIQ.Where(x => x.Birthday >= DateTime.Now.AddYears((userPreferences.MaxAge * -1)) &&
                                                          x.Birthday <= DateTime.Now.AddYears((userPreferences.MinAge * -1)));

            // Filters passed and liked users
            IQueryable <ApplicationUser> FilterUsers(List <string> keywords)
            {
                var predicate = PredicateBuilder.New <ApplicationUser>();

                foreach (var keyword in keywords)
                {
                    predicate = predicate.And(p => !p.Id.Contains(keyword));
                }
                return(applicationUsersIQ.Where(predicate));
            }

            var applicationUserPass = await _db.Pass.Where(x => x.ApplicationUserID == userId).ToListAsync();

            var applicationUserLiked = await _db.Liked.Where(x => x.ApplicationUserID == userId).ToListAsync();

            List <string> filterUsers = new List <string>()
            {
                userId
            };

            foreach (var item in applicationUserPass)
            {
                filterUsers.Add(item.ApplicationUserPassID.ToString());
            }
            foreach (var item in applicationUserLiked)
            {
                filterUsers.Add(item.ApplicationUserLikedID.ToString());
            }

            applicationUsersIQ = FilterUsers(filterUsers);

            int pageSize = 3;
            PaginatedList <ApplicationUser> paginatedListUsers = await PaginatedList <ApplicationUser> .CreateAsync(
                applicationUsersIQ,
                pageNumber ?? 1,
                pageSize);

            var auth = new FirebaseAuthProvider(new FirebaseConfig(FirebaseKeys.apiKey));
            var a    = await auth.SignInWithEmailAndPasswordAsync(FirebaseKeys.AuthEmail, FirebaseKeys.AuthPassword);

            for (int i = 0; i < paginatedListUsers.Count; i++)
            {
                if (paginatedListUsers[i].ProfileImage != "/images/avatar/default_avatar.png")
                {
                    paginatedListUsers[i].FirebaseProfileImageURL = new FirebaseStorage(
                        FirebaseKeys.Bucket,
                        new FirebaseStorageOptions
                    {
                        AuthTokenAsyncFactory = () => Task.FromResult(a.FirebaseToken),
                        ThrowOnCancel         = true
                    })
                                                                    .Child("images")
                                                                    .Child($"{paginatedListUsers[i].ProfileImage}")
                                                                    .GetDownloadUrlAsync().Result;
                }
            }

            // Get random user to display
            ApplicationUser featuredUser   = new ApplicationUser();
            int             listUsersCount = paginatedListUsers.Count();

            if (listUsersCount > 0)
            {
                Random random       = new Random();
                int    randomNumber = random.Next(listUsersCount);
                string randomUserId = paginatedListUsers[randomNumber].Id;

                IQueryable <ApplicationUser> featuredUserIQ = _db.ApplicationUser;
                featuredUser = await featuredUserIQ
                               .Include(x => x.Height)
                               .Include(x => x.About)
                               .FirstOrDefaultAsync(x => x.Id == randomUserId);
            }

            HomeViewModel homeViewModel = new HomeViewModel()
            {
                PaginatedListUsers = paginatedListUsers,
                FeaturedUser       = featuredUser,
                Liked = new Liked(),
                Pass  = new Pass()
            };

            return(View(homeViewModel));
        }
        AtomFeed SearchInAtom(NameValueCollection parameters)
        {
            var alternate = (feed != null && feed.Links != null) ? feed.Links.FirstOrDefault(l => l.RelationshipType == "alternate") : null;
            if(alternate == null) alternate = feed.Links.FirstOrDefault(l => l.RelationshipType == "self");

            string[] queryString = Array.ConvertAll(parameters.AllKeys, key => String.Format("{0}={1}", key, parameters[key]));

            AtomFeed resultfeed = new AtomFeed("Discovery feed for " + this.Identifier,
                                         "This OpenSearch Service allows the discovery of the different items which are part of the " + this.Identifier + " collection" +
                                         "This search service is in accordance with the OGC 10-032r3 specification.",
                                               alternate != null ? alternate.Uri : new Uri(feed.Id) , feed.Id, DateTimeOffset.UtcNow);

            resultfeed.Generator = "Terradue Web Server";

            // Load all avaialable Datasets according to the context

            PaginatedList<AtomItem> pds = new PaginatedList<AtomItem>();

            int startIndex = 1;
            if (!string.IsNullOrEmpty(parameters["startIndex"]))
                startIndex = int.Parse(parameters["startIndex"]);

            pds.AddRange(SearchInItem((IEnumerable < AtomItem > )feed.Items, parameters));

            pds.PageNo = 1;
            if (!string.IsNullOrEmpty(parameters["startPage"]))
                pds.PageNo = int.Parse(parameters["startPage"]);

            pds.PageSize = 20;
            if (!string.IsNullOrEmpty(parameters["count"]))
                pds.PageSize = int.Parse(parameters["count"]);

            pds.StartIndex = startIndex - 1;

            if (this.Identifier != null)
                resultfeed.Identifier = this.Identifier;

            resultfeed.Items = pds.GetCurrentPage();
            resultfeed.TotalResults = pds.Count(); ;

            return resultfeed;
        }
示例#4
0
 public ActionResult Editor(int id, int? page)
 {
     var blogs = new PaginatedList<Blog>(rep.BlogsDoUsuario(id), page ?? 0, 5);
     if (blogs.Count() > 0)
         ViewData["Editor"] = blogs.FirstOrDefault().Editor.Nome;
     rep.Dispose();
     return View(blogs);
 }
        private AtomFeed GenerateSyndicationFeed(NameValueCollection parameters)
        {
            UriBuilder myUrl = new UriBuilder("file:///test");
            string[] queryString = Array.ConvertAll(parameters.AllKeys, key => String.Format("{0}={1}", key, parameters[key]));
            myUrl.Query = string.Join("&", queryString);

            AtomFeed feed = new AtomFeed("Discovery feed for " + this.Identifier,
                                         "This OpenSearch Service allows the discovery of the different items which are part of the " + this.Identifier + " collection" +
                                         "This search service is in accordance with the OGC 10-032r3 specification.",
                                         myUrl.Uri, myUrl.ToString(), DateTimeOffset.UtcNow);

            feed.Generator = "Terradue Web Server";

            List<AtomItem> items = new List<AtomItem>();

            // Load all avaialable Datasets according to the context

            PaginatedList<TestItem> pds = new PaginatedList<TestItem>();

            int startIndex = 1;
            if (parameters["startIndex"] != null)
                startIndex = int.Parse(parameters["startIndex"]);

            pds.StartIndex = startIndex;
            pds.AddRange(Items);

            pds.PageNo = 1;
            if (parameters["startPage"] != null)
                pds.PageNo = int.Parse(parameters["startPage"]);

            pds.PageSize = 20;
            if (parameters["count"] != null)
                pds.PageSize = int.Parse(parameters["count"]);

            if (this.Identifier != null)
                feed.Identifier = this.Identifier;

            foreach (TestItem s in pds.GetCurrentPage()) {

                if (s is IAtomizable) {
                    AtomItem item = (s as IAtomizable).ToAtomItem(parameters);
                    if (item != null)
                        items.Add(item);
                } else {

                    string fIdentifier = s.Identifier;
                    string fName = s.Name;
                    string fText = (s.TextContent != null ? s.TextContent : "");

                    if (!string.IsNullOrEmpty(parameters["q"])) {
                        string q = parameters["q"];
                        if (!(fName.Contains(q) || fIdentifier.Contains(q) || fText.Contains(q)))
                            continue;
                    }

                    Uri alternate = new Uri("file:///test/search?count=0&id=" + fIdentifier);
                    Uri id = new Uri(s.Id);

                    AtomItem entry = new AtomItem(fIdentifier, fName, alternate, id.ToString(), s.Date);
                    entry.PublishDate = s.Date.DateTime;
                    entry.LastUpdatedTime = s.Date.DateTime;
                    entry.Categories.Add(new SyndicationCategory(this.Identifier));

                    entry.Summary = new TextSyndicationContent(fName);
                    entry.ElementExtensions.Add("identifier", "http://purl.org/dc/elements/1.1/", fIdentifier);

                    items.Add(entry);
                }
            }

            feed.Items = items;
            var tr = pds.Count();
            feed.TotalResults = tr;

            return feed;
        }
示例#6
0
 public ActionResult Editor(int id, int? page)
 {
     var artigos = new PaginatedList<Artigo>(rep.ArtigosDoUsuario(id), page ?? 0, 5);
     if (artigos.Count() > 0)
         ViewData["Editor"] = artigos.FirstOrDefault().Editor.Nome;
     rep.Dispose();
     return View(artigos);
 }