public GetRefListsRequest( long?authorId, string authorUserName, long?tagUseId, string tagName, string titleSearch, DateTime?fromDate, PublishingStatusConditionKind publishingStatusCondition, int pageIndex, int pageSize, RefListSortKind sort ) { AuthorId = authorId; AuthorUserName = authorUserName; TagUseId = tagUseId; TagName = tagName; TitleSearch = titleSearch; FromDate = fromDate; PublishingStatusCondition = publishingStatusCondition; PageIndex = pageIndex; PageSize = pageSize; Sort = sort; }
public async Task <ActionResult> Narrow( int pageIndex, int pageSize = WebConsts.RefListsPageSize, RefListSortKind sort = RefListSortKind.PublishedDateDescending ) { var user = GetUser(); var cond = new PageCondition(pageIndex - 1, pageSize); var result = await _favoriteHandler.GetAllFavoriteRefListsAsync(user.Id, cond, sort); var vm = Mapper.Map <PagedRefListsViewModel>(result); return(JsonNet(vm, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> NarrowManage( string titleSearch = "", string tag = null, PublishingStatusConditionKind publishingStatusCondition = PublishingStatusConditionKind.All, int pageIndex = 1, RefListSortKind sort = RefListSortKind.UpdatedDateDescending ) { var user = GetUser(); var vm = await PrepareManagePageViewModel( user.Id, null, titleSearch, tag, publishingStatusCondition, pageIndex - 1, WebConsts.RefListsPageSize, sort ); return(JsonNet(vm, JsonRequestBehavior.AllowGet)); }
private async Task <ManagePageViewModel> PrepareManagePageViewModel( long?authorId, string userName, string titleSearch, string tag, PublishingStatusConditionKind publishingStatusCondition, int pageIndex, int pageSize, RefListSortKind sort ) { var req = new GetRefListsRequest( authorId, userName, null, tag, titleSearch, null, publishingStatusCondition, pageIndex, pageSize, sort ); var resp = await _refListHandler.GetRefListsAsync(req); var vm = Mapper.Map <ManagePageViewModel>(resp); ++vm.PageIndex; vm.TitleSearch = titleSearch; vm.TagUse = tag; return(vm); }
public async Task <ActionResult> NarrowIndex( long?authorId, string titleSearch = "", string tag = "", int pageIndex = 1, RefListSortKind sort = RefListSortKind.PublishedDateDescending ) { var req = new GetRefListsRequest( authorId, null, null, tag, titleSearch, null, PublishingStatusConditionKind.PublishOnly, pageIndex - 1, WebConsts.RefListsPageSize, sort ); var result = await _refListHandler.GetRefListsAsync(req); var vm = new IndexPageViewModel() { Tag = tag, PageIndex = result.PageIndex + 1, PageCount = result.PageCount, RefLists = Mapper.Map <ICollection <RefListViewModel> >(result.RefLists), }; return(JsonNet(vm, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> NarrowDetail( string tag, string titleSearch = "", int pageIndex = 1, RefListSortKind sort = RefListSortKind.PublishedDateDescending ) { SystemContract.RequireNotNull(tag, "tag"); SystemContract.Require(tag != CoreConsts.UnsetTagName, "$unsetが指定されました"); /// 非公開設定の確認のため本人でもPublishしか見れないようにする。 var req = new GetRefListsRequest( null, null, null, tag, titleSearch, null, PublishingStatusConditionKind.PublishOnly, pageIndex - 1, WebConsts.RefListsPageSize, sort ); var result = await _refListHandler.GetRefListsAsync(req); var vm = new PagedRefListsViewModel() { PageIndex = result.PageIndex + 1, PageCount = result.PageCount, RefLists = Mapper.Map <ICollection <RefListViewModel> >(result.RefLists), }; return(JsonNet(vm, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> NarrowDetail( long?id, string titleSearch = "", string tag = null, int pageIndex = 1, RefListSortKind sort = RefListSortKind.PublishedDateDescending ) { SystemContract.RequireNotNull(id, "id"); //var isPublishOnly = !IsCurrentUserId(id.Value); /// Author以外のユーザーの場合、Publishなリストだけを対象にする /// 非公開設定の確認のため本人でもPublishしか見れないようにする。 var req = new GetRefListsRequest( id.Value, null, null, tag, titleSearch, null, PublishingStatusConditionKind.PublishOnly, pageIndex - 1, WebConsts.RefListsPageSize, sort ); var result = await _refListHandler.GetRefListsAsync(req); var vm = new PagedRefListsViewModel() { PageIndex = result.PageIndex + 1, PageCount = result.PageCount, RefLists = Mapper.Map <ICollection <RefListViewModel> >(result.RefLists), }; return(JsonNet(vm, JsonRequestBehavior.AllowGet)); }
public async Task <PagedRefLists> GetAllFavoriteRefListsAsync(long ownerId, PageCondition pageCondition, RefListSortKind sort) { var refListIdsQuery = _refsContext.Favorites. Where(f => f.OwnerId == ownerId && f.Kind == FavoriteKind.RefList). Select(f => f.RefListId.Value); var refListIds = await refListIdsQuery.ToArrayAsync(); var tagIdsQuery = _refsContext.Favorites. Where(f => f.OwnerId == ownerId && f.Kind == FavoriteKind.Tag). Select(f => f.TagId.Value); var tagIds = await tagIdsQuery.ToArrayAsync(); var userIdsQuery = _refsContext.Favorites. Where(f => f.OwnerId == ownerId && f.Kind == FavoriteKind.User). Select(f => f.UserId.Value); var userIds = await userIdsQuery.ToArrayAsync(); var query = _refsContext.RefLists.AsNoTracking(). Where(l => l.PublishingStatus == PublishingStatusKind.Publish && ( refListIds.Contains(l.Id) || tagIds.Intersect(l.TagUses.Select(u => u.TagId)).Any() || userIds.Contains(l.AuthorId) ) ); var refListCount = await query.CountAsync(); query = QueryUtil.AppendQueryForRefListSort(query, sort); query = query.Skip(pageCondition.PageIndex * pageCondition.PageSize); query = query.Take(pageCondition.PageSize); var storedRefList = await query.ToArrayAsync(); return(new PagedRefLists() { PageIndex = pageCondition.PageIndex, PageCount = IndexUtil.GetPageCount(refListCount, pageCondition.PageSize), RefLists = storedRefList, AllRefListCount = refListCount, }); }
public static IQueryable <RefList> AppendQueryForRefListSort(IQueryable <RefList> query, RefListSortKind sort) { switch (sort) { case RefListSortKind.UpdatedDateDescending: query = query.OrderByDescending(l => l.UpdatedDate); break; case RefListSortKind.UpdatedDateAscending: query = query.OrderBy(l => l.UpdatedDate); break; case RefListSortKind.CreatedDateDescending: query = query.OrderByDescending(l => l.CreatedDate); break; case RefListSortKind.CreatedDateAscending: query = query.OrderBy(l => l.CreatedDate); break; case RefListSortKind.PublishedDateDescending: query = query.OrderByDescending(l => l.PublishedDate); break; case RefListSortKind.FavoriteCountDescending: query = query. OrderByDescending(l => l.Statistics.FavoriteCount).ThenByDescending(l => l.PublishedDate); break; case RefListSortKind.ViewCountDescending: query = query. OrderByDescending(l => l.Statistics.ViewCount).ThenByDescending(l => l.PublishedDate); break; } return(query); }