Exemplo n.º 1
0
        // AdminReviewedSources

        public AdminReviewedSource GetOrCreateAdminReviewedSource(int sourceId, int adminSourceSearchId)
        {
            Source            source = this.sourceTasks.GetSource(sourceId);
            AdminSourceSearch ass    = this.adminSourceSearchRepository.Get(adminSourceSearchId);

            IDictionary <string, object> criteria = new Dictionary <string, object>();

            criteria.Add("Source", source);
            criteria.Add("AdminSourceSearch", ass);
            AdminReviewedSource ars = this.adminReviewedSourceRepository.FindOne(criteria);

            if (ars == null)
            {
                // TODO when creating a new Reviewed record, this source might be marked relevant in another
                // equivalent search.  However this new Review will be more recent.
                // We could prompt the user to remind them to mark it as relevant when they review the source...
                ars = new AdminReviewedSource();
                ars.ReviewedDateTime  = DateTime.Now;
                ars.Source            = source;
                ars.AdminSourceSearch = ass;
                ars.Archive           = false;
                ars = this.adminReviewedSourceRepository.SaveOrUpdate(ars);
            }
            return(ars);
        }
Exemplo n.º 2
0
        // TODO the criteria for finding previous searches is a little inflexible here.
        public IList <int> GetAdminSourceSearchIds(AdminSourceSearch adminSourceSearch)
        {
            var qo = Session.QueryOver <AdminSourceSearch>();

            if (!string.IsNullOrEmpty(adminSourceSearch.AndSearchTerms))
            {
                qo.Where(x => x.AndSearchTerms == adminSourceSearch.AndSearchTerms ||
                         x.AndSearchTerms == string.Join(" ", adminSourceSearch.AndSearchTermsQuoted));
                if (!string.IsNullOrEmpty(adminSourceSearch.ExcludeSearchTerms))
                {
                    qo.And(x => x.ExcludeSearchTerms == adminSourceSearch.ExcludeSearchTerms ||
                           x.ExcludeSearchTerms == string.Join(" ", adminSourceSearch.ExcludeSearchTermsQuoted));
                }

                return(qo.Select(x => x.Id).List <int>());
            }
            else
            {
                // OrSearchTerms still ignored.
                return(new List <int>());
            }
        }
Exemplo n.º 3
0
 public IList <int> GetAdminSourceSearchIds(AdminSourceSearch adminSourceSearch)
 {
     return(this.adminSourceSearchQuery.GetAdminSourceSearchIds(adminSourceSearch));
 }
Exemplo n.º 4
0
 public AdminSourceSearch SaveOrUpdateAdminSourceSearch(AdminSourceSearch adminSourceSearch)
 {
     return(this.adminSourceSearchRepository.SaveOrUpdate(adminSourceSearch));
 }
Exemplo n.º 5
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
            }));
        }
        public ActionResult Details(int id)
        {
            AdminSourceSearch model = this.sourceAttachmentTasks.GetAdminSourceSearch(id);

            return(View(model));
        }