Пример #1
0
        /// <summary>
        ///     Performs a search when the requirements have been met
        /// </summary>
        public IOrderedQueryable <SporeServerAsset> PerformSearch()
        {
            var searchText = Request.Query["searchText"].ToString();

            // no need to do anything when
            // there's no search string
            if (String.IsNullOrEmpty(searchText))
            {
                return(null);
            }

            var  searchFieldsQuery = Request.Query["searchFields"];
            bool searchName        = searchFieldsQuery.Contains("name");
            bool searchAuthor      = searchFieldsQuery.Contains("author");
            bool searchTags        = searchFieldsQuery.Contains("tags");
            bool searchDescription = searchFieldsQuery.Contains("description");

            // no need to perform a search
            // when no search field has been specified
            if (!searchName &&
                !searchAuthor &&
                !searchTags &&
                !searchDescription)
            {
                return(null);
            }

            // perform actual search
            return(_assetManager.GetAllAssets()
                   .Include(a => a.Author)
                   .Include(a => a.Tags)
                   .Where(a => a.Used &&
                          (
                              (searchName && a.Name.Contains(searchText)) ||
                              (searchAuthor && a.Author.UserName.Contains(searchText)) ||
                              (searchTags && a.Tags.Where(t => t.Tag.Contains(searchText)).FirstOrDefault() != null) ||
                              (searchDescription && a.Description.Contains(searchText))
                          )
                          ).OrderBy(a => a.Name));
        }
Пример #2
0
 public List <Asset> GetAllAssets()
 {
     return(_assetManager.GetAllAssets());
 }
        public async Task <IActionResult> OnGet(Int32?index)
        {
            Console.WriteLine($"/community/assetBrowser/createSporecast/{index}{Request.QueryString}");

            string searchString = Request.Query["searchText"];
            string filterString = Request.Query["filter"];

            SearchString = searchString;
            FilterString = filterString;

            bool searchName = !String.IsNullOrEmpty(searchString);
            bool searchModelType = false, searchAssetType = false;

            // if we can parse filterString, make sure we can use it
            if (Int64.TryParse(filterString, out Int64 filterId))
            {
                searchModelType = Enum.IsDefined(typeof(SporeModelType), filterId);
                searchAssetType = Enum.IsDefined(typeof(SporeAssetType), filterId);
            }

            // search the assets using LINQ
            var queryAssets = _assetManager.GetAllAssets()
                              .Include(a => a.Author)
                              .Where(a => a.Used &&
                                     (
                                         (
                                             (!searchName) ||
                                             (
                                                 a.Author.UserName.Contains(searchString) ||
                                                 a.Name.Contains(searchString)
                                             )
                                         )
                                         &&
                                         (
                                             (searchModelType && a.ModelType == (SporeModelType)filterId) ||
                                             (searchAssetType && a.Type == (SporeAssetType)filterId) ||
                                             (!searchModelType && !searchAssetType)
                                         )
                                     )
                                     ).OrderBy(a => a.Name);

            CurrentIndex  = index ?? 0;
            NextIndex     = CurrentIndex + 8;
            PreviousIndex = CurrentIndex - 8;

            SearchCount = await queryAssets
                          .CountAsync();

            Assets = await queryAssets
                     .Skip(CurrentIndex)
                     .Take(8)
                     .ToArrayAsync();

            AssetCount = Assets.Length;

            string name        = Request.Query["scName"];
            string description = Request.Query["scDesc"];

            // when name isn't defined, return the page
            // if it is defined, attempt to add the aggregator
            if (String.IsNullOrEmpty(name))
            {
                return(Page());
            }

            // loop over each asset query
            // and add valid ones to the assets list
            var assets = new List <SporeServerAsset>();

            foreach (var assetString in Request.Query["asset"])
            {
                if (Int64.TryParse(assetString, out Int64 assetId))
                {
                    var asset = await _assetManager.FindByIdAsync(assetId, true);

                    if (asset != null)
                    {
                        assets.Add(asset);
                    }
                }
            }

            // make sure the aggregator has assets
            if (assets.Count == 0)
            {
                return(Page());
            }

            // add aggregator
            var author = await _userManager.GetUserAsync(User);

            var aggregator = await _aggregatorManager.AddAsync(author, name, description, assets.ToArray());

            if (aggregator == null)
            {
                return(StatusCode(500));
            }

            // redirect to /pollinator/atom/aggregator/{id}
            return(Redirect($"https://pollinator.spore.com/pollinator/atom/aggregator/{aggregator.AggregatorId}"));
        }