Esempio n. 1
0
        /// <summary>
        /// 创建标签
        /// </summary>
        /// <param name="tag">待创建的标签</param>
        /// <param name="logoStream">标题图文件流</param>
        /// <returns>创建成功返回true,否则返回false</returns>
        public bool Create(T tag, Stream logoStream = null)
        {
            //创建数据前,触发相关事件
            EventBus <T> .Instance().OnBefore(tag, new CommonEventArgs(EventOperationType.Instance().Create()));

            long tagId = Convert.ToInt64(tagRepository.Insert(tag));

            if (tagId > 0)
            {
                AddTagInOwner(tag.TagName, tag.TenantTypeId, tag.OwnerId);
                if (logoStream != null)
                {
                    //上传Logo
                    LogoService logoService = new LogoService(TenantTypeIds.Instance().Tag());
                    tag.FeaturedImage = logoService.UploadLogo(tagId, logoStream);
                    tagRepository.Update(tag);
                }
                //若创建成功,触发创建后相关事件
                EventBus <T> .Instance().OnAfter(tag, new CommonEventArgs(EventOperationType.Instance().Create()));

                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// 创建评论
        /// </summary>
        /// <param name="comment">待创建评论</param>
        /// <returns>创建成功返回true,否则返回false</returns>
        public bool Create(Comment comment)
        {
            //触发事件
            EventBus <Comment> .Instance().OnBefore(comment, new CommonEventArgs(EventOperationType.Instance().Create()));

            AuditService auditService = new AuditService();

            auditService.ChangeAuditStatusForCreate(comment.UserId, comment);


            //评论创建
            long commentId = Convert.ToInt64(commentRepository.Insert(comment));


            //更新父级ChildCount
            if (commentId > 0)
            {
                ICommentBodyProcessor commentBodyProcessor = DIContainer.Resolve <ICommentBodyProcessor>();
                comment.Body = commentBodyProcessor.Process(comment.Body, TenantTypeIds.Instance().Comment(), commentId, comment.UserId);
                commentRepository.Update(comment);

                commentRepository.UpdateChildCount(comment.ParentId, false);
                CountService countService = new CountService(comment.TenantTypeId);
                countService.ChangeCount(CountTypes.Instance().CommentCount(), comment.CommentedObjectId, comment.OwnerId, 1, true);
                //触发事件
                EventBus <Comment> .Instance().OnAfter(comment, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <Comment, AuditEventArgs> .Instance().OnAfter(comment, new AuditEventArgs(null, comment.AuditStatus));
            }

            return(commentId > 0);
        }
Esempio n. 3
0
        /// <summary>
        /// 删除标签
        /// </summary>
        /// <param name="tagId">标签Id</param>
        /// <returns>删除成功返回true,否则返回false</returns>
        public bool Delete(long tagId)
        {
            T tag = tagRepository.Get(tagId);

            int affectCount = 0;

            if (tag != null)
            {
                //删除数据前,触发相关事件
                EventBus <T> .Instance().OnBefore(tag, new CommonEventArgs(EventOperationType.Instance().Delete()));

                affectCount = tagRepository.Delete(tag);
                if (affectCount > 0)
                {
                    //删除Logo
                    LogoService logoService = new LogoService(TenantTypeIds.Instance().Tag());
                    logoService.DeleteLogo(tagId);

                    //若删除成功,触发删除后相关事件
                    EventBus <T> .Instance().OnAfter(tag, new CommonEventArgs(EventOperationType.Instance().Delete()));

                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
        //关于缓存期限:
        //1、PointItem实体、列表 使用CachingExpirationType.RelativelyStable
        //2、PointCategory实体、列表 使用CachingExpirationType.RelativelyStable
        //3、PointRecord实体、列表 使用正常的缓存策略
        //4、积分记录的所有积分类型都是0,则不创建

        #region 积分变更及记录

        /// <summary>
        /// 依据规则增减积分
        /// </summary>
        /// <param name="userId">增减积分的UserId</param>
        /// <param name="pointItemKey">积分项目标识</param>
        /// <param name="description">积分记录描述</param>
        public void GenerateByRole(long userId, string pointItemKey, string description)
        {
            //1、依据pointItemKey查找积分项目,如果未找到则中断执行;
            PointItem pointItem = GetPointItem(pointItemKey);

            if (pointItem == null)
            {
                return;
            }
            if (pointItem.ExperiencePoints == 0 && pointItem.ReputationPoints == 0 && pointItem.TradePoints == 0)
            {
                return;
            }
            //2、检查用户当日各类积分是否达到限额,如果达到限额则不加积分,如果未达到则更新当日积分限额
            Dictionary <string, int> dictionary = pointStatisticRepository.UpdateStatistic(userId, GetPointCategory2PointsDictionary(pointItem));

            //如果用户当日各类积分都超出限额,则不产生积分
            if (dictionary.Count(n => n.Value != 0) == 0)
            {
                return;
            }

            //3、按照pointItemKey对应的积分项目,生成积分记录,并对用户积分额进行增减;

            int experiencePoints = dictionary[PointCategoryKeys.Instance().ExperiencePoints()];
            int reputationPoints = dictionary[PointCategoryKeys.Instance().ReputationPoints()];
            int tradePoints      = dictionary[PointCategoryKeys.Instance().TradePoints()];
            int tradePoints2     = 0;
            int tradePoints3     = 0;
            int tradePoints4     = 0;

            if (dictionary.ContainsKey("TradePoints2"))
            {
                tradePoints2 = dictionary["TradePoints2"];
            }
            if (dictionary.ContainsKey("TradePoints3"))
            {
                tradePoints3 = dictionary["TradePoints3"];
            }
            if (dictionary.ContainsKey("TradePoints4"))
            {
                tradePoints4 = dictionary["TradePoints4"];
            }

            PointRecord pointRecord = new PointRecord(userId, pointItem.ItemName, description, experiencePoints, reputationPoints, tradePoints);

            pointRecord.TradePoints2 = tradePoints2;
            pointRecord.TradePoints3 = tradePoints3;
            pointRecord.TradePoints4 = tradePoints4;
            pointRecordRepository.Insert(pointRecord);
            IUserService userService = DIContainer.Resolve <IUserService>();

            userService.ChangePoints(userId, experiencePoints, reputationPoints, tradePoints, tradePoints2, tradePoints3, tradePoints4);

            CountService countService = new CountService(TenantTypeIds.Instance().User());

            countService.ChangeCount(CountTypes.Instance().ReputationPointsCounts(), userId, userId, pointRecord.ReputationPoints);
        }
Esempio n. 5
0
 /// <summary>
 /// 上传广告图片
 /// </summary>
 /// <param name="advertising">广告实体</param>
 /// <param name="stream">图片流</param>
 private void UploadAdvertisingImage(Advertising advertising, Stream stream)
 {
     if (stream != null)
     {
         LogoService logoService = new LogoService(TenantTypeIds.Instance().Advertising());
         advertising.AttachmentUrl = logoService.UploadLogo(advertising.AdvertisingId, stream);
         advertisingRepository.Update(advertising);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// 上传示意图
 /// </summary>
 /// <param name="position">广告位</param>
 /// <param name="stream">图片流</param>
 private void UploadPositionImage(AdvertisingPosition position, Stream stream)
 {
     if (stream != null)
     {
         LogoService logoService = new LogoService(TenantTypeIds.Instance().AdvertisingPosition());
         position.FeaturedImage = logoService.UploadLogo(position.PositionId, stream);
         advertisingPositionRepository.Update(position);
     }
 }
Esempio n. 7
0
 /// <summary>
 /// 上传Logo
 /// </summary>
 /// <param name="recommendId">推荐Id</param>
 /// <param name="stream">Logo文件流</param>
 public void UploadLogo(long recommendId, Stream stream)
 {
     if (stream != null)
     {
         RecommendItem recommend   = this.Get(recommendId);
         LogoService   logoService = new LogoService(TenantTypeIds.Instance().Recommend());
         recommend.FeaturedImage = logoService.UploadLogo(recommendId, stream);
         this.Update(recommend);
     }
 }
Esempio n. 8
0
 public static TenantTypeIds Instance()
 {
     if (_instance == null)
     {
         lock (lockObject)
         {
             if (_instance == null)
             {
                 _instance = new TenantTypeIds();
             }
         }
     }
     return(_instance);
 }
Esempio n. 9
0
 public static TenantTypeIds Instance()
 {
     if (_instance == null)
     {
         lock (lockObject)
         {
             if (_instance == null)
             {
                 _instance = new TenantTypeIds();
             }
         }
     }
     return _instance;
 }
Esempio n. 10
0
        /// <summary>
        /// 删除广告位示意图
        /// </summary>
        /// <param name="positionId">广告位Id</param>
        public void DeletePositionImage(string positionId)
        {
            LogoService logoService = new LogoService(TenantTypeIds.Instance().AdvertisingPosition());

            logoService.DeleteLogo(positionId);

            AdvertisingPosition position = GetPosition(positionId);

            if (position == null)
            {
                return;
            }

            position.FeaturedImage = string.Empty;
            advertisingPositionRepository.Update(position);
        }
Esempio n. 11
0
        /// <summary>
        /// 删除广告位
        /// </summary>
        /// <param name="positionId"></param>
        /// <returns></returns>
        public bool DeletePosition(string positionId)
        {
            AdvertisingPosition position = advertisingPositionRepository.Get(positionId);
            int result = advertisingPositionRepository.Delete(position);

            if (result > 0)
            {
                LogoService logoService = new LogoService(TenantTypeIds.Instance().AdvertisingPosition());
                logoService.DeleteLogo(positionId);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// 更新标签
        /// </summary>
        /// <param name="tag">待创建的标签</param>
        /// <param name="logoStream">标题图文件流</param>
        /// <returns></returns>
        public void Update(T tag, Stream logoStream = null)
        {
            //若更新据前,触发相关事件
            EventBus <T> .Instance().OnBefore(tag, new CommonEventArgs(EventOperationType.Instance().Update()));

            //上传Logo
            if (logoStream != null)
            {
                LogoService logoService = new LogoService(TenantTypeIds.Instance().Tag());
                tag.FeaturedImage = logoService.UploadLogo(tag.TagId, logoStream);
            }

            tagRepository.Update(tag);

            //若更新成功,触发创建后相关事件
            EventBus <T> .Instance().OnAfter(tag, new CommonEventArgs(EventOperationType.Instance().Update()));
        }
Esempio n. 13
0
        /// <summary>
        /// 删除广告示意图
        /// </summary>
        /// <param name="advertisingId">广告Id</param>
        public void DeleteAdvertisingImage(long advertisingId)
        {
            LogoService logoService = new LogoService(TenantTypeIds.Instance().Advertising());

            logoService.DeleteLogo(advertisingId);

            Advertising advertising = GetAdvertising(advertisingId);

            if (advertising == null)
            {
                return;
            }
            if (advertising.AdvertisingType == AdvertisingType.Image)
            {
                advertising.AttachmentUrl = string.Empty;
            }

            advertisingRepository.Update(advertising);
        }
Esempio n. 14
0
        /// <summary>
        /// 删除广告
        /// </summary>
        /// <param name="advertisingId">广告Id</param>
        /// <returns></returns>
        public bool DeleteAdvertising(long advertisingId)
        {
            Advertising advertising = advertisingRepository.Get(advertisingId);
            int         result      = advertisingRepository.Delete(advertising);

            if (result > 0)
            {
                ClearPositionsFromAdvertising(advertisingId);

                LogoService logoService = new LogoService(TenantTypeIds.Instance().Advertising());
                logoService.DeleteLogo(advertisingId);

                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 验证指定对象针对toUserId是否具有隐私权限
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="toUserId">被验证用户</param>
        /// <param name="specifyObjectId">指定对象Id</param>
        /// <returns>true-成功,false-失败</returns>
        bool IPrivacySpecifyObjectValidator.Validate(long userId, long toUserId, long specifyObjectId)
        {
            //done:zhengw,by mazq
            //1、所有分组Id是什么?
            //2、相互关注等特殊规则怎么制定的,编码的人遵照什么来编码
            //zhengw回复:使用FollowSpecifyGroupIds.All获取所有分组Id,具体参见:Examples\BusinessComponents\User\Follow\FollowEnum.cs中的FollowSpecifyGroupIds类

            //如果specifyObjectId为所有分组Id,则仅判断下toUserId是不是关注的人即可
            FollowService followService = new FollowService();

            if (specifyObjectId == FollowSpecifyGroupIds.All)
            {
                return(followService.IsFollowed(userId, toUserId));
            }
            else if (specifyObjectId == FollowSpecifyGroupIds.Mutual)
            {
                return(followService.IsMutualFollowed(userId, toUserId));
            }
            else
            {
                FollowEntity follow = followService.Get(userId, toUserId);
                if (follow == null)
                {
                    return(false);
                }
                IEnumerable <Category> categories = new CategoryService().GetCategoriesOfItem(follow.Id, userId, TenantTypeIds.Instance().User());
                if (categories == null)
                {
                    return(false);
                }
                return(categories.Any(n => n.CategoryId == specifyObjectId));
            }
        }
Esempio n. 16
0
        /// <summary>
        /// 删除Logo
        /// </summary>
        /// <param name="recommendId">推荐Id</param>
        public void DeleteLogo(long recommendId)
        {
            LogoService logoService = new LogoService(TenantTypeIds.Instance().Recommend());

            logoService.DeleteLogo(recommendId);
        }
Esempio n. 17
0
        /// <summary>
        /// 判断是否关注了被判定用户
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="toUserId">被判定用户Id</param>
        /// <param name="groupNames">被关注用户所属分组</param>
        /// <returns>true-关注,false-没关注</returns>
        public bool IsFollowed(long userId, long toUserId, out IEnumerable <string> groupNames)
        {
            bool isFollow = followRepository.IsFollowed(userId, toUserId);

            groupNames = null;
            if (isFollow)
            {
                FollowEntity followEntity = followRepository.Get(userId, toUserId);
                groupNames = categoryService.GetCategoriesOfItem(followEntity.Id, userId, TenantTypeIds.Instance().User()).Select(n => n.CategoryName);
            }

            return(isFollow);
        }
Esempio n. 18
0
        /// <summary>
        /// 解析内容用于创建话题
        /// </summary>
        /// <param name="body">待解析的内容</param>
        /// <param name="ownerId">标签拥有者Id</param>
        /// <param name="associateId">关联项Id</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        public void ResolveBodyForEdit(string body, long ownerId, long associateId, string tenantTypeId)
        {
            if (!body.Contains("#") || string.IsNullOrEmpty(body))
            {
                return;
            }

            Regex rg = new Regex(@"(?<=(?<!\&)(\#)(?!\d\;))[^\#@]*(?=(?<!\&)(\#)(?![0-9]+\;))", RegexOptions.Multiline | RegexOptions.Singleline);
            Match m  = rg.Match(body);

            if (!m.Success)
            {
                return;
            }

            IList <string> tagNames = new List <string>();
            int            i = 0, index = -1;

            while (m != null)
            {
                if (i % 2 == 1)
                {
                    m = m.NextMatch();
                    i++;
                    continue;
                }

                if (index == m.Index)
                {
                    break;
                }

                index = m.Index;

                if (!string.IsNullOrEmpty(m.Value) && !tagNames.Contains(m.Value))
                {
                    tagNames.Add(m.Value);
                }
                else
                {
                    continue;
                }

                m = m.NextMatch();
                i++;
            }

            if (tagNames.Count > 0)
            {
                CountService countService = new CountService(TenantTypeIds.Instance().Tag());
                AddTagsToItem(tagNames.ToArray(), ownerId, associateId);

                Dictionary <string, long> tagNamesWithIds = GetTagNamesWithIdsOfItem(associateId);
                if (tagNamesWithIds != null)
                {
                    foreach (KeyValuePair <string, long> pair in tagNamesWithIds)
                    {
                        countService.ChangeCount(CountTypes.Instance().ItemCounts(), pair.Value, ownerId, 1);
                    }
                }
            }
        }