コード例 #1
0
ファイル: Default.aspx.cs プロジェクト: adlnet/3D-Repository
    /// <summary>
    /// 
    /// </summary>
    /// <param name="c"></param>
    protected void BindViewData(Control c)
    {
        PermissionsManager permManager = new PermissionsManager();
        string username = HttpContext.Current.User.Identity.Name;

        //You gotta love how FindControl isn't recursive...
        DataList list = (DataList)c.FindControl("RotatorLayoutTable")
                                        .FindControl("RotatorListViewRow")
                                            .FindControl("RotatorListViewColumn")
                                                .FindControl("RotatorListView");

        ISearchProxy permissionsHonoringProxy = new DataAccessFactory().CreateSearchProxy(HttpContext.Current.User.Identity.Name);

        switch (c.ID)
        {
            case "HighestRatedRotator":
                list.DataSource = permissionsHonoringProxy.GetByRating(4);
                break;

            case "MostPopularRotator":
                list.DataSource = permissionsHonoringProxy.GetByViews(4);
                break;

            case "RecentlyUpdatedRotator":
                list.DataSource = permissionsHonoringProxy.GetByLastUpdated(4);
                break;

            case "RandomRotator":
                list.DataSource = permissionsHonoringProxy.GetByRandom(4);
                break;

            default:
                throw new Exception("No control '" + c.ID + "' could be found to bind data to.");
        }
        list.DataBind();
        permissionsHonoringProxy.Dispose();
        permManager.Dispose();
    }
コード例 #2
0
    private IEnumerable<ContentObject> GetSearchResults()
    {
        IEnumerable<ContentObject> co = null;
        vwarDAL.ISearchProxy _SearchProxy = new DataAccessFactory().CreateSearchProxy(Context.User.Identity.Name);
        SearchMethod method;
        string methodParam = Request.QueryString["Method"];
        if (!String.IsNullOrEmpty(methodParam) && methodParam.ToLowerInvariant() == "and")
            method = SearchMethod.AND;
        else
            method = SearchMethod.OR;

        if (!String.IsNullOrEmpty(Request.QueryString["Search"]))
        {
            string searchTerm = Request.QueryString["Search"];
            if (!String.IsNullOrEmpty(searchTerm))
            {
                SearchTextBox.Text = Server.UrlDecode(searchTerm);
                if (SearchTextBox.Text.Contains(','))
                {
                    var terms = SearchTextBox.Text.Split(',');
                    co = _SearchProxy.QuickSearch(terms, method);
                }
                else
                {
                    co = _SearchProxy.QuickSearch(SearchTextBox.Text);
                }
            }
        }
        else if (!String.IsNullOrEmpty(Request.QueryString["Group"]))
        {
            /* Here, we are getting "everything" (limit NumResultsPerPage) by a grouping.

               By doing a little processing ahead of time, we can
               avoid having to use ApplySort when unnecessary, as well
               as reduce the size of the data returned from MySQL.
            */

            string[] sortParams = SortInfo.Split('-');
            if (sortParams.Length == 2) //Make sure it's in the right format!
            {
                SortOrder order = (sortParams[1].ToLowerInvariant() == "low")
                  ? SortOrder.Ascending
                  : SortOrder.Descending;

                int start = (_PageNumber - 1) * _ResultsPerPage;

                switch (sortParams[0].ToLowerInvariant())
                {
                    case "views":
                        co = _SearchProxy.GetByViews(_ResultsPerPage, start, order);
                        break;

                    case "updated":
                        co = _SearchProxy.GetByLastUpdated(_ResultsPerPage, start, order);
                        break;

                    case "viewed":
                        co = _SearchProxy.GetByLastViewed(_ResultsPerPage, start, order);
                        break;

                    case "rating":
                    default:
                        co = _SearchProxy.GetByRating(_ResultsPerPage, start, order);
                        break;
                }
                _Presorted = true;
            }
        }
        else //We're searching by field
        {
            System.Collections.Specialized.NameValueCollection fieldsToSearch = new System.Collections.Specialized.NameValueCollection();

            string[] searchableFields = { "Title", "Description", "ArtistName", "SponsorName", "DeveloperName", "Keywords" };

            foreach (string field in searchableFields)
                if (!String.IsNullOrEmpty(Request.QueryString[field]))
                    fieldsToSearch[field] = Server.UrlDecode(Request.QueryString[field]);

            co = _SearchProxy.SearchByFields(fieldsToSearch, method);
        }

        _SearchProxy.Dispose();
        return co;
    }