Beispiel #1
0
        public PartialFindResult <ActivityEntryForApiContract> GetList(
            DateTime?before                    = null,
            DateTime?since                     = null,
            int?userId                         = null,
            EntryEditEvent?editEvent           = null,
            int maxResults                     = defaultMax,
            bool getTotalCount                 = false,
            ActivityEntryOptionalFields fields = ActivityEntryOptionalFields.None,
            EntryOptionalFields entryFields    = EntryOptionalFields.None,
            ContentLanguagePreference lang     = ContentLanguagePreference.Default)
        {
            maxResults = Math.Min(maxResults, absoluteMax);
            bool ssl = WebHelper.IsSSL(Request);

            return(repository.HandleQuery(ctx => {
                var query = ctx.Query <ActivityEntry>();

                if (before.HasValue && !since.HasValue)
                {
                    query = query.Where(a => a.CreateDate < before.Value);
                }

                if (!before.HasValue && since.HasValue)
                {
                    query = query.Where(a => a.CreateDate > since.Value);
                }

                if (before.HasValue && since.HasValue)
                {
                    query = query.Where(a => a.CreateDate > since.Value && a.CreateDate < before.Value);
                }

                if (userId.HasValue)
                {
                    query = query.Where(a => a.Author.Id == userId.Value);
                }

                if (editEvent.HasValue)
                {
                    query = query.Where(a => a.EditEvent == editEvent.Value);
                }

                var activityEntries = query
                                      .OrderByDescending(a => a.CreateDate)
                                      .Take(maxResults)
                                      .ToArray()
                                      .Where(a => !a.EntryBase.Deleted)
                                      .Select(a => new ActivityEntryForApiContract(a,
                                                                                   fields.HasFlag(ActivityEntryOptionalFields.Entry) ? entryForApiContractFactory.Create(a.EntryBase, entryFields, lang, ssl) : null,
                                                                                   userIconFactory, permissionContext, fields))
                                      .ToArray();

                var count = getTotalCount ? query.Count() : 0;

                return PartialFindResult.Create(activityEntries, count);
            }));
        }
        public ActivityEntryForApiContract(ActivityEntry activityEntry, EntryForApiContract entryForApiContract,
                                           IUserIconFactory userIconFactory,
                                           IUserPermissionContext permissionContext,
                                           ActivityEntryOptionalFields fields)
        {
            CreateDate = activityEntry.CreateDate.ToUniversalTime();
            EditEvent  = activityEntry.EditEvent;

            if (activityEntry.Author != null &&
                ((permissionContext.IsLoggedIn && (permissionContext.LoggedUserId == activityEntry.Author.Id || permissionContext.HasPermission(PermissionToken.DisableUsers))) ||
                 !activityEntry.Author.AnonymousActivity))
            {
                Author = new UserForApiContract(activityEntry.Author, userIconFactory, UserOptionalFields.MainPicture);
            }

            if (fields.HasFlag(ActivityEntryOptionalFields.ArchivedVersion) && activityEntry.ArchivedVersionBase != null)
            {
                ArchivedVersion = new ArchivedObjectVersionForApiContract(activityEntry.ArchivedVersionBase);
            }

            Entry = entryForApiContract;
        }