Пример #1
0
        public IQueryable <ShareInfo> QueryShareList(ShareQuery shareQuery)
        {
            //IQueryable<ShareInfo> statement = CurrentDB.ShareInfos.AsNoTracking();

            IQueryable <OneNote> noteSQL = CurrentDB.ShareInfos.OfType <OneNote>().Where(o => o.ShareOrNot == true);
            IQueryable <DayPlan> planSQL = CurrentDB.ShareInfos.OfType <DayPlan>().Where(o => o.ShareOrNot == true);

            //if (shareQuery.OnlyMyself)
            //{
            //    var userId = CurrentPrincipal.UserId;
            //    statement = statement.Where(o => o.UserId == userId);
            //}

            if (shareQuery.IncludeNote)
            {
                if (shareQuery.OnlyMyself)
                {
                    var userId = CurrentPrincipal.UserId;

                    noteSQL = noteSQL.Where(o => o.UserId == userId);
                }

                if (!string.IsNullOrWhiteSpace(shareQuery.Text))
                {
                    noteSQL =
                        noteSQL.Where(o => o.Content.Contains(shareQuery.Text) || o.Title.Contains(shareQuery.Text));
                }

                if (shareQuery.IncludePlan == false)
                {
                    return(noteSQL.OrderByDescending(o => o.UpdateAt));
                }
            }

            if (shareQuery.IncludePlan)
            {
                if (shareQuery.OnlyMyself)
                {
                    var userId = CurrentPrincipal.UserId;

                    planSQL = planSQL.Where(o => o.UserId == userId);
                }

                if (!string.IsNullOrWhiteSpace(shareQuery.Text))
                {
                    planSQL =
                        planSQL.Where(o => o.Content.Contains(shareQuery.Text));
                }

                if (shareQuery.IncludeNote == false)
                {
                    return(planSQL.OrderByDescending(o => o.UpdateAt));
                }
            }

            return(planSQL.OfType <ShareInfo>().Concat(noteSQL.OfType <ShareInfo>())
                   .OrderByDescending(o => o.UpdateAt));
        }
 /// <summary>
 /// Check <see cref="ICollectionService"/> for more information
 /// </summary>
 /// <param name="query">Check <see cref="ICollectionService"/> for more information</param>
 /// <returns>Check <see cref="ICollectionService"/> for more information</returns>
 public async Task ShareCollectionAsync(ShareQuery query)
 {
     await _requestSender.SendRequestAsync(new ApiRequest
     {
         Path       = $"/api/v4/collections/{query.CollectionId}/share/",
         HTTPMethod = HttpMethod.Post,
         Query      = query,
     }).ConfigureAwait(false);
 }
Пример #3
0
        /// <summary>
        /// Check <see cref="ICollectionsManager"/> for more information
        /// </summary>
        /// <param name="query">Check <see cref="ICollectionsManager"/> for more information</param>
        /// <returns>Check <see cref="ICollectionsManager"/> for more information</returns>
        public Task ShareCollectionAsync(ShareQuery query)
        {
            var request = new Request <string>
            {
                Uri                 = $"/api/v4/collections/{query.CollectionId}/share/",
                HTTPMethod          = HttpMethod.Post,
                Query               = query,
                DeserializeResponse = false
            };

            return(_requestSender.SendRequestAsync(request));
        }
Пример #4
0
        public async Task ShareCollectionAsyncCallsRequestSenderWithValidRequest()
        {
            var result = new { message = "Accepted", statuscode = 202 };

            _apiRequestSenderMock.Setup(sender => sender.SendRequestAsync(It.IsAny <ApiRequest>()))
            .ReturnsAsync(result);
            var shareQuery = new ShareQuery("collectionId", new List <string>(), SharingPermission.View);
            await _collectionService.ShareCollectionAsync(shareQuery);

            _apiRequestSenderMock.Verify(sender => sender.SendRequestAsync(
                                             It.Is <ApiRequest>(
                                                 req => req.Path == $"/api/v4/collections/{shareQuery.CollectionId}/share/" &&
                                                 req.Query == shareQuery &&
                                                 req.HTTPMethod == HttpMethod.Post
                                                 )
                                             ));
        }
Пример #5
0
        public async Task ShareCollectionAsyncCallsRequestSenderWithValidRequest()
        {
            var apiRequestSender = new Mock <IApiRequestSender>();
            var result           = "";

            apiRequestSender.Setup(sender => sender.SendRequestAsync(It.IsAny <Request <string> >()))
            .Returns(Task.FromResult(result));
            var collectionService = new CollectionService(apiRequestSender.Object);
            var shareQuery        = new ShareQuery("collectionId", new List <string>(), SharingPermission.View);
            await collectionService.ShareCollectionAsync(shareQuery);

            apiRequestSender.Verify(sender => sender.SendRequestAsync(
                                        It.Is <Request <string> >(
                                            req => req.Path == $"/api/v4/collections/{shareQuery.CollectionId}/share/" &&
                                            req.Query == shareQuery &&
                                            req.HTTPMethod == HttpMethod.Post &&
                                            req.DeserializeResponse == false)));
        }
Пример #6
0
        public async Task WhenShareAsyncCalledContainsExpectedResult(string id, string emailAddresses)
        {
            IList <string> recipients = emailAddresses.Split(',');

            var query = new ShareQuery(id, recipients, SharingPermission.View);

            IList <string> mediaList = new List <string>();
            var            mock      = new Mock <IOauthRequestSender>();

            mock.Setup(reqSenderMock => reqSenderMock.SendRequestAsync(It.IsAny <Request <string> >())).Returns(Task.FromResult(string.Empty));

            var manager = new CollectionsManager(mock.Object);
            await manager.ShareCollectionAsync(query);

            mock.Verify(reqSenderMock
                        => reqSenderMock.SendRequestAsync(It.Is <Request <string> >(req => req.Uri == $"/api/v4/collections/{id}/share/" &&
                                                                                    req.HTTPMethod == HttpMethod.Post &&
                                                                                    ((ShareQuery)req.Query).Recipients.Count == recipients.Count &&
                                                                                    ((ShareQuery)req.Query).Permission == SharingPermission.View)));
        }
Пример #7
0
        public JsonResult Query(ShareQuery query)
        {
            if (query == null)
            {
                return(Json(false));
            }

            var statement = shareService.QueryShareList(query);

            Func <ShareInfo, ShareableContent> tranform = o =>
            {
                shareService.LoadIsMyPraised(o);

                var result = new ShareableContent(o);

                return(result);
            };

            return(Json(JsonDataList.CreateTransformResult(statement, tranform, query.Offset, query.Limit > 0 ? query.Limit : 4)));
        }