Exemplo n.º 1
0
        /// <summary>
        /// 访客访问了某内容
        /// </summary>
        /// <param name="visitorId">访客用户Id</param>
        /// <param name="visitor">访客名称</param>
        /// <param name="toObjectId">被访问对象Id</param>
        /// <param name="toObjectName">被访问对象名称</param>
        /// <remarks>如果记录已经存在,则更新</remarks>
        public void CreateVisit(long visitorId, string visitor, long toObjectId, string toObjectName)
        {
            Visit visit = visitRepository.Get(tenantTypeId, visitorId, toObjectId);

            if (visit == null)
            {
                visit = Visit.New();
                visit.TenantTypeId = tenantTypeId;
                visit.VisitorId    = visitorId;
                visit.Visitor      = visitor;
                visit.ToObjectId   = toObjectId;
                visit.ToObjectName = toObjectName;
                EventBus <Visit> .Instance().OnBefore(visit, new CommonEventArgs(EventOperationType.Instance().Create()));

                visitRepository.Insert(visit);
                EventBus <Visit> .Instance().OnAfter(visit, new CommonEventArgs(EventOperationType.Instance().Create()));
            }
            else
            {
                visit.Visitor       = visitor;
                visit.ToObjectName  = toObjectName;
                visit.LastVisitTime = DateTime.UtcNow;
                EventBus <Visit> .Instance().OnBefore(visit, new CommonEventArgs(EventOperationType.Instance().Update()));

                visitRepository.Update(visit);
                EventBus <Visit> .Instance().OnAfter(visit, new CommonEventArgs(EventOperationType.Instance().Update()));
            }
        }
Exemplo n.º 2
0
        public async Task <Page <Visit> > Get(PageRequest pageRequest)
        {
            var increasedTake = pageRequest.Take++;
            var visitEntities = await visitRepository.Get(pageRequest.Skip, increasedTake, pageRequest.Query);

            var visits     = visitEntities.Select(v => v.ToModel()).ToArray();
            var hasMore    = visits.Length == increasedTake;
            int?totalCount = null;

            if (pageRequest.Count)
            {
                totalCount = await visitRepository.GetTotalCount();
            }

            return(new Page <Visit>
            {
                Items = visits,
                HasMore = hasMore,
                TotalCount = totalCount
            });
        }