public new object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            SourceDataTablesParam p = new SourceDataTablesParam((DataTablesParam)base.BindModel(controllerContext, bindingContext));

            NameValueCollection @params = controllerContext.HttpContext.Request.Params;

            p.searchAdminSourceSearchId = string.IsNullOrEmpty(@params["searchAdminSourceSearchId"]) ? null : (int?)Convert.ToInt32(@params["searchAdminSourceSearchId"]);
            p.searchText       = string.IsNullOrEmpty(@params["searchText"]) ? null : @params["searchText"].Trim();
            p.searchId         = string.IsNullOrEmpty(@params["searchId"]) ? null : (int?)Convert.ToInt32(@params["searchId"]);
            p.personId         = string.IsNullOrEmpty(@params["personId"]) ? null : (int?)Convert.ToInt32(@params["personId"]);
            p.eventId          = string.IsNullOrEmpty(@params["eventId"]) ? null : (int?)Convert.ToInt32(@params["eventId"]);
            p.startDate        = string.IsNullOrEmpty(@params["startDate"]) ? null : @params["startDate"].Trim();
            p.endDate          = string.IsNullOrEmpty(@params["endDate"]) ? null : @params["endDate"].Trim();
            p.searchName       = string.IsNullOrEmpty(@params["searchName"]) ? null : @params["searchName"].Trim();
            p.searchExtension  = string.IsNullOrEmpty(@params["searchExtension"]) ? null : @params["searchExtension"].Trim();
            p.authorSearchText = string.IsNullOrEmpty(@params["authorSearchText"]) ? null : @params["authorSearchText"].Trim();
            return(p);
        }
Exemplo n.º 2
0
        public JsonNetResult DataTables(SourceDataTablesParam p)
        {
            int iTotalRecords = 0;
            IList <SourceDataTableView> aaData = new List <SourceDataTableView>();

            // get or create new AdminSourceSearch for this search
            AdminUser         user = this.userTasks.GetAdminUser(this.User.Identity.Name);
            AdminSourceSearch adminSourceSearch;

            if (p.searchAdminSourceSearchId.HasValue && p.searchAdminSourceSearchId.Value > 0)
            {
                adminSourceSearch = this.sourceAttachmentTasks.GetAdminSourceSearch(p.searchAdminSourceSearchId.Value);
            }
            else
            {
                adminSourceSearch = new AdminSourceSearch(p.searchText);
                adminSourceSearch.SearchedByAdminUser = user;
                adminSourceSearch = this.sourceAttachmentTasks.SaveOrUpdateAdminSourceSearch(adminSourceSearch);
            }

            if (p.searchId.HasValue)
            {
                // bypasses NHibernate OutOfMemoryError, but doesn't populate IsAttached
                SourceDTO dto = this.sourceTasks.GetSourceDTO(p.searchId.Value);

                if (dto != null)
                {
                    aaData.Add(new SourceDataTableView(dto));
                    iTotalRecords = 1;
                    adminSourceSearch.NumOfMatchingSources = 1;
                }
            }
            else
            {
                // get past searches in order to use their relevance ratings
                IList <int> adminSourceSearchIds = this.sourceAttachmentTasks.GetAdminSourceSearchIds(adminSourceSearch);

                IList <SourceSearchResultDTO> sources = null;
                if (((PrfPrincipal)User).HasPermission(AdminPermission.CanViewAndSearchAllSources))
                {
                    iTotalRecords = this.sourceTasks.GetSearchTotal(
                        ((PrfPrincipal)User).HasPermission(AdminPermission.CanViewAndSearchRestrictedSources),
                        p.searchName,
                        p.searchExtension,
                        adminSourceSearch.FullTextSearchTerm,
                        p.GetStartDate(),
                        p.GetEndDate(),
                        p.authorSearchText);
                    sources = this.sourceTasks.GetPaginatedResults(
                        ((PrfPrincipal)User).HasPermission(AdminPermission.CanViewAndSearchRestrictedSources),
                        p.iDisplayStart, p.iDisplayLength,
                        p.searchName,
                        p.searchExtension,
                        adminSourceSearch.FullTextSearchTerm,
                        p.GetStartDate(),
                        p.GetEndDate(),
                        adminSourceSearchIds,
                        p.iSortingCols, p.iSortCol, p.sSortDir,
                        user.Id, p.personId, p.eventId,
                        p.authorSearchText);
                }
                else
                {
                    throw new NotImplementedException();
                }

                foreach (SourceSearchResultDTO x in sources)
                {
                    aaData.Add(new SourceDataTableView(x));
                }

                adminSourceSearch.NumOfMatchingSources = iTotalRecords;
                this.sourceAttachmentTasks.SaveOrUpdateAdminSourceSearch(adminSourceSearch);
            }

            return(JsonNet(new DataTablesSourceData
            {
                iTotalRecords = iTotalRecords,
                iTotalDisplayRecords = iTotalRecords,
                sEcho = p.sEcho,
                aaData = aaData.ToArray(),
                adminSourceSearchId = adminSourceSearch.Id
            }));
        }