예제 #1
0
        public async Task <IActionResult> Index()
        {
            var moviesFromCache = await _cache.GetSearchResultAsync("movies");

            var Movie = collection.Find(FilterDefinition <Movies> .Empty).ToList();

            if (moviesFromCache != null)
            {
                if (moviesFromCache.Count < Movie.Count && moviesFromCache.Count > Movie.Count)
                {
                    List <Movies> list = collection.Find(FilterDefinition <Movies> .Empty).ToList();

                    await _cache.AddSearchResultsAsync("movies", list, 12);

                    return(View(await _cache.GetSearchResultAsync("movies")));
                }
                else
                {
                    return(View(moviesFromCache));
                }
            }
            else
            {
                List <Movies> list = collection.Find(FilterDefinition <Movies> .Empty).ToList();

                await _cache.AddSearchResultsAsync("movies", list, 12);

                return(View(await _cache.GetSearchResultAsync("movies")));
            }
        }
        // public async Task<IList<Itinerary>> Search([FromBody] SearchCriteria criteria)
        // {
        //     var flights = await FlightDataSource.FindFlightsAsync(criteria);
        //  return flights;
        // }

        public async Task <IList <Itinerary> > Search([FromBody] SearchCriteria criteria)
        {
            // returns something like "FlightFinder/Search/LHR/SEA/2020-07-02.00:00:00Z/2020-07-09.00:00:00Z/Economy"
            var searchId = criteria.GetSearchId();

            var flights = await cache.GetSearchResultsAsync(searchId);

            if (flights == null)
            {
                flights = await FlightDataSource.FindFlightsAsync(criteria);

                await cache.AddSearchResultsAsync(searchId, flights);
            }

            return(flights);
        }
예제 #3
0
        public async Task <IActionResult> Index()
        {
            //get the current earner  email and id

            var email  = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email).Value;
            var userid = User.Claims.FirstOrDefault(c => c.Type == AppUtility.UserId).Value;

            CollectionView collectionView = new CollectionView(); //initialize the viewmodel

            BadgeExpiryCheck(email);

            //get the info of logged in earner
            var             earnerBadges = EarnerBadgeDetails.Find(e => e.RecipientEmail == email).ToList();
            List <BackPack> list         = new List <BackPack>();

            #region Redis
            var earnerId = await _cache.GetSearchResultAsync(userid);

            if (earnerId != null)
            {
                collectionView.BackPacks = earnerId;
            }

            else
            {
                if (earnerBadges.Count() != null)
                {
                    List <int> add_list = new List <int>();
                    for (var k = 0; k < earnerBadges.Count(); k++)
                    {
                        var badgeid          = earnerBadges[k].BadgeId;
                        var badgedetailsnew  = Badge.Find(e => e.BadgeId == earnerBadges[k].BadgeId).FirstOrDefault();
                        var issuerids        = badgedetailsnew.IssuerId;
                        var issuerdetailsnew = Issuers.Find(e => e.IssuerId == issuerids).FirstOrDefault();
                        var facebookid       = Badge.Find(e => e.BadgeId == badgeid).FirstOrDefault().FacebookId;

                        BackPack b = new BackPack()
                        {
                            BadgeName          = badgedetailsnew.BadgeName,
                            earningDescription = badgedetailsnew.EarningCriteriaDescription,
                            ImageUrl           = badgedetailsnew.ImageUrl,
                            IssuerName         = issuerdetailsnew.Name,
                            badgeid            = badgeid.ToString(),
                            FacebookId         = facebookid,
                            IsExpired          = earnerBadges[k].IsExpired
                        };

                        list.Add(b);
                        DateTime expireDuration = earnerBadges[k].ExpirationDate.Date;
                        DateTime dtNow          = DateTime.Now;
                        TimeSpan result         = expireDuration.Subtract(dtNow);
                        int      seconds        = Convert.ToInt32(result.TotalSeconds);
                        add_list.Add(seconds);
                    }
                    int[] secondsForTotalBadge = add_list.ToArray();

                    if (list.Count > 0)
                    {
                        await _cache.AddSearchResultsAsync(userid, list, secondsForTotalBadge.Min());
                    }
                    collectionView.BackPacks = list;
                }
            }
            #endregion
            collectionView.BadgeCollections = BadgeCollections.Find(e => e.UserId == new ObjectId(userid)).ToList();

            #region showing badge in collection
            var totalBadgeCollection = BadgeCollections.Find(e => e.UserId == new ObjectId(userid)).ToList();
            var totalBadgeImage      = new List <BadgeImage>();
            if (totalBadgeCollection != null)
            {
                for (int badgeColl = 0; badgeColl < totalBadgeCollection.Count; badgeColl++)
                {
                    string[] b = totalBadgeCollection[badgeColl].BadgeId;
                    if (b != null)
                    {
                        for (var n = 0; n < b.Length; n++)
                        {
                            DigiBadges.DataAccess.Badge bdg = _badges.FindById(b[n]);

                            if (b[n].ToString() == bdg.Id.ToString())
                            {
                                BadgeImage badgeImage = new BadgeImage()
                                {
                                    ID       = b[n].ToString(),
                                    ImageUrl = bdg.ImageUrl
                                };
                                totalBadgeImage.Add(badgeImage);
                            }
                        }
                    }
                }
            }
            collectionView.BI = totalBadgeImage;
            #endregion


            return(View(collectionView));
        }
예제 #4
0
        public async Task <IActionResult> Index(SearchVM ssvm)
        {
            if (ssvm.FirstName != null || ssvm.LastName != null || ssvm.Email != null)
            {
                SearchCriteria criteria = new SearchCriteria();

                criteria.FirstName = ssvm.FirstName;
                criteria.LastName  = ssvm.LastName;
                criteria.Email     = ssvm.Email;


                var searchId = criteria.GetSearchId();

                var usersVal = await cache.GetSearchResultsAsync(searchId);

                if (usersVal == null)
                {
                    // string fname = criteria.FirstName;
                    // string lname = criteria.LastName;
                    // string email = criteria.Email;

                    string fname = string.Empty;
                    string lname = string.Empty;
                    string email = string.Empty;

                    if (!string.IsNullOrEmpty(criteria.FirstName))
                    {
                        fname = "*" + criteria.FirstName + "*";
                    }
                    if (!string.IsNullOrEmpty(criteria.LastName))
                    {
                        lname = "*" + criteria.LastName + "*";
                    }
                    if (!string.IsNullOrEmpty(criteria.Email))
                    {
                        email = "*" + criteria.Email + "*";
                    }


                    string query = "FirstName:'" + criteria.FirstName + "' OR " + " LastName:'" + criteria.LastName + "'" + " OR " + " Email:'" + criteria.Email + "'";


                    // var query = Query.Field("FirstName").Is(criteria.FirstName) || Query.Field("LastName").Is(LastName)|| Query.Field("Email").Is(Email);
                    //var results = solr.Query(query);


                    ssvm.usrList = GellSelectedQuery(query);

                    await cache.AddSearchResultsAsync(searchId, ssvm.usrList);
                }
                else
                {
                    ssvm.usrList = new List <SolrUsersModel>();

                    foreach (SolrUsersModel uss in usersVal)
                    {
                        ssvm.usrList.Add(uss);
                    }
                }

                return(View(ssvm));
            }
            else
            {
                ssvm.usrList = GetAllQuery();
                return(View(ssvm));
            }
        }