Beispiel #1
0
        private IList <TResource> GetRecentResources <TResource>(Guid userId, IEnumerable <TResource> resources, IEnumerable <Resource> excludeResources)
            where TResource : Resource
        {
            var recentResources = excludeResources == null
                ? resources.Take(2).ToList()
                : (from r in resources
                       where excludeResources.All(x => x.Id != r.Id)
                   select r).Take(2).ToList();

            for (var index = 0; index < recentResources.Count; ++index)
            {
                var viewing = new ResourceViewing
                {
                    ResourceType = typeof(TResource) == typeof(Article)
                        ? ResourceType.Article
                        : typeof(TResource) == typeof(Video)
                            ? ResourceType.Video
                            : ResourceType.QnA,
                    UserId     = userId,
                    ResourceId = recentResources[index].Id,
                    Id         = Guid.NewGuid(),
                    Time       = DateTime.Now.AddDays(-1 * (index + 1)),
                };
                _resourcesRepository.CreateResourceViewing(viewing);
            }

            return(recentResources);
        }
Beispiel #2
0
        private void ViewResource(ResourceType resourceType, Guid userId, Guid resourceId)
        {
            var viewing = new ResourceViewing {
                ResourceType = resourceType, UserId = userId, ResourceId = resourceId
            };

            viewing.Prepare();
            viewing.Validate();
            _repository.CreateResourceViewing(viewing);

            var handlers = ResourceViewed;

            if (handlers != null)
            {
                handlers(this, new ResourceEventArgs(viewing.ResourceId));
            }
        }