예제 #1
0
        /// <summary>
        /// 删除分类同内容的关联项
        /// </summary>
        /// <param name="categoryId">分类Id</param>
        /// <param name="itemId">内容项Id</param>
        /// <param name="ownerId">拥有者Id</param>
        public int DeleteItemInCategory(long categoryId, long itemId, long ownerId)
        {
            //声明PetaPoco的SqlBuilder
            var sql = PetaPoco.Sql.Builder;

            //组装sql
            sql.Append("delete tn_ItemsInCategories  where CategoryId=@0 and ItemId=@1", categoryId, itemId);


            //执行语句
            int effectLineCount = CreateDAO().Execute(sql);

            #region 处理缓存

            if (effectLineCount > 0)
            {
                //ItemId分区缓存
                RealTimeCacheHelper.IncreaseAreaVersion("ItemId", itemId);
                //本分区缓存,作用是:供其他服务或者应用来更新缓存
                RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", ownerId);
                //CategoryId分区缓存
                RealTimeCacheHelper.IncreaseAreaVersion("CategoryId", categoryId);
            }
            #endregion

            return(effectLineCount);
        }
예제 #2
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>影响的记录数</returns>
        public override int Delete(SearchedTerm entity)
        {
            int record = base.Delete(entity);

            RealTimeCacheHelper.IncreaseAreaVersion("SearchTypeCode", entity.SearchTypeCode);
            return(record);
        }
예제 #3
0
        /// <summary>
        /// 移动相片
        /// </summary>
        /// <param name="photo">被移动的照片</param>
        /// <param name="targetAlbum">接收的相册</param>
        /// <returns>是否移动成功</returns>
        public bool MovePhoto(Photo photo, Album targetAlbum)
        {
            AlbumRepository albumRepository = new AlbumRepository();

            if (photo.UserId != targetAlbum.UserId || photo.AlbumId == targetAlbum.AlbumId)
            {
                return(false);
            }

            photo.Album.PhotoCount--;

            //更新原相册数据
            if (photo.Album.CoverId == photo.PhotoId)
            {
                photo.Album.CoverId = 0;
            }

            albumRepository.Update(photo.Album);

            RealTimeCacheHelper.IncreaseAreaVersion("AlbumId", photo.AlbumId);

            //更新照片所属相册以及继承属性
            photo.AlbumId       = targetAlbum.AlbumId;
            photo.TenantTypeId  = targetAlbum.TenantTypeId;
            photo.OwnerId       = targetAlbum.OwnerId;
            photo.PrivacyStatus = targetAlbum.PrivacyStatus;
            Update(photo);


            //更新目标相册
            targetAlbum.PhotoCount++;
            albumRepository.Update(targetAlbum);
            return(true);
        }
예제 #4
0
        /// <summary>
        /// 创建提醒记录
        /// </summary>
        /// <param name="userId">被提醒用户Id</param>
        /// <param name="reminderMode">提醒方式</param>
        /// <param name="reminderInfoType">提醒信息类型</param>
        /// <param name="objectIds">提醒对象Id集合</param>
        public void CreateRecords(long userId, int reminderMode, int reminderInfoType, IEnumerable <long> objectIds)
        {
            PetaPocoDatabase dao = CreateDAO();

            dao.OpenSharedConnection();
            var sql = Sql.Builder;

            sql.Select("ObjectId")
            .From("tn_ReminderRecords")
            .Where("UserId=@0", userId)
            .Where("ReminderModeId=@0", reminderMode)
            .Where("ReminderInfoTypeId=@0", reminderInfoType);

            IEnumerable <object> oldObjectIds_object = dao.FetchFirstColumn(sql);
            IEnumerable <long>   oldObjectIds        = oldObjectIds_object.Cast <long>();

            foreach (var objectId in objectIds)
            {
                if (!oldObjectIds.Contains(objectId))
                {
                    ReminderRecord record = ReminderRecord.New();
                    record.UserId             = userId;
                    record.ReminderModeId     = reminderMode;
                    record.ReminderInfoTypeId = reminderInfoType;
                    record.ObjectId           = objectId;
                    dao.Insert(record);
                }
            }

            dao.CloseSharedConnection();

            //更新缓存
            RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
        }
예제 #5
0
        /// <summary>
        /// 删除标签与成员的关系实体
        /// </summary>
        /// <param name="entity">待处理的实体</param>
        /// <returns></returns>
        public override int Delete(ItemInTag entity)
        {
            PetaPocoDatabase dao = CreateDAO();

            dao.OpenSharedConnection();

            int affectCount = base.Delete(entity);

            if (entity != null && affectCount > 0)
            {
                List <Sql> sqls = new List <Sql>();
                sqls.Add(Sql.Builder.Append("update tn_TagsInOwners set ItemCount = ItemCount - 1")
                         .Where("ItemCount > 0 and Id = @0", entity.TagInOwnerId));
                sqls.Add(Sql.Builder.Append("update tn_Tags set ItemCount = ItemCount - 1")
                         .Where("ItemCount > 0 and TagName = @0 and TenantTypeId = @1", entity.TagName, entity.TenantTypeId));

                affectCount = dao.Execute(sqls);

                RealTimeCacheHelper.IncreaseAreaVersion("TagName", entity.TagName);
                RealTimeCacheHelper.IncreaseAreaVersion("ItemId", entity.ItemId);
            }

            dao.CloseSharedConnection();

            return(affectCount);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override object Insert(RecommendItemType entity)
        {
            object typeId = base.Insert(entity);

            RealTimeCacheHelper.IncreaseAreaVersion("TenantTypeId", string.Empty);
            return(typeId);
        }
예제 #7
0
        /// <summary>
        /// 从用户收件箱移除动态
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="activityId">动态Id</param>
        public void DeleteFromUserInbox(long userId, long activityId)
        {
            Sql sql = Sql.Builder.Append("delete from tn_ActivityUserInbox where UserId=@0 and ActivityId=@1 ", userId, activityId);

            CreateDAO().Execute(sql);
            RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
        }
예제 #8
0
        /// <summary>
        /// 取消收藏
        /// </summary>
        /// <param name="objectId">被收藏对象Id</param>
        /// <param name="userId">用户Id</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <returns>true-取消成功,false-取消失败</returns>
        public bool CancelFavorited(long objectId, long userId, string tenantTypeId)
        {
            if (IsFavorited(objectId, userId, tenantTypeId))
            {
                Sql sql = Sql.Builder;
                sql.Append("delete from tn_Favorites where UserId = @0 and ObjectId = @1 and TenantTypeId = @2", userId, objectId, tenantTypeId);
                int affectCount = CreateDAO().Execute(sql);
                if (affectCount > 0)
                {
                    RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
                    string       cacheKey  = GetCacheKey_AllFavorites(userId, tenantTypeId);
                    IList <long> objectIds = cacheService.Get <IList <long> >(cacheKey);
                    if (objectIds != null && objectIds.Contains(objectId))
                    {
                        objectIds.Remove(objectId);
                        cacheService.Set(cacheKey, objectIds, CachingExpirationType.UsualObjectCollection);
                    }

                    cacheKey = GetCacheKey_AllUserIdOfObject(objectId, tenantTypeId);
                    IList <long> userIds = cacheService.Get <IList <long> >(cacheKey);
                    if (userIds != null && userIds.Contains(userId))
                    {
                        userIds.Remove(userId);
                        cacheService.Set(cacheKey, userIds, CachingExpirationType.UsualObjectCollection);
                    }

                    return(true);
                }
            }

            return(false);
        }
예제 #9
0
        /// <summary>
        ///  删除用户发布的评论
        /// </summary>
        /// <remarks>
        /// 供用户删除时处理用户相关信息时调用
        /// </remarks>
        /// <param name="userId">UserId</param>
        /// <param name="reserveCommnetsAsAnonymous">true=保留用户发布的评论,但是修改为匿名用户;false=直接删除评论</param>
        /// <returns></returns>
        public int DeleteUserComments(long userId, bool reserveCommnetsAsAnonymous)
        {
            var sql = PetaPoco.Sql.Builder;

            if (reserveCommnetsAsAnonymous)
            {
                sql.Append("UPDATE tn_Comments  SET UserId=0");
            }
            else
            {
                sql.Append("DELETE FROM tn_Comments ");
            }

            sql.Where("UserId=@0", userId);
            int rows = CreateDAO().Execute(sql);

            #region 处理缓存
            if (rows > 0)
            {
                RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
            }
            #endregion

            return(rows);
        }
예제 #10
0
        /// <summary>
        /// 批量添加分组给标签
        /// </summary>
        /// <param name="groupIds">分组Id集合</param>
        /// <param name="tagName">标签名</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        public int BatchAddGroupsToTag(IEnumerable <long> groupIds, string tagName, string tenantTypeId)
        {
            int affectCount = 0;

            PetaPocoDatabase dao = CreateDAO();

            dao.OpenSharedConnection();

            dao.Execute(Sql.Builder.Append("delete from tn_TagsInGroups where tagName = @0 and TenantTypeId = @1", tagName, tenantTypeId));

            IList <PetaPoco.Sql> sqls = new List <PetaPoco.Sql>();

            foreach (var groupId in groupIds)
            {
                //if (groupId <= 0)
                //    continue;

                sqls.Add(Sql.Builder.Append("INSERT INTO tn_TagsInGroups (GroupId, TagName,TenantTypeId) VALUES (@0,@1,@2)", groupId, tagName, tenantTypeId));
            }
            affectCount = dao.Execute(sqls);

            if (affectCount > 0)
            {
                groupIds.ToList().ForEach(n =>
                {
                    RealTimeCacheHelper.IncreaseAreaVersion("GroupId", n);
                });

                EntityData.ForType(typeof(TagGroup)).RealTimeCacheHelper.IncreaseAreaVersion("TenantTypeId", tenantTypeId);
            }
            dao.CloseSharedConnection();

            return(affectCount);
        }
예제 #11
0
        /// <summary>
        /// 添加标签与分组关联
        /// </summary>
        /// <param name="tagName">标签名</param>
        /// <param name="groupId">拥有者Id</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        public int AddTagInGroup(string tagName, long groupId, string tenantTypeId)
        {
            PetaPocoDatabase dao = CreateDAO();

            int affectCount = 0;

            dao.OpenSharedConnection();

            var sql = PetaPoco.Sql.Builder;

            sql.Select("count(*)")
            .From("tn_TagsInGroups")
            .Where("GroupId = @0", groupId)
            .Where("TagName = @0", tagName)
            .Where("TenantTypeId = @0", tenantTypeId);

            affectCount = dao.ExecuteScalar <int>(sql);
            if (affectCount == 0)
            {
                sql = PetaPoco.Sql.Builder;
                sql.Append("INSERT INTO tn_TagsInGroups (GroupId, TagName,TenantTypeId) VALUES (@0,@1,@2)", groupId, tagName, tenantTypeId);
                affectCount = dao.Execute(sql);

                if (affectCount > 0)
                {
                    RealTimeCacheHelper.IncreaseAreaVersion("GroupId", groupId);
                }
            }

            dao.CloseSharedConnection();

            return(affectCount);
        }
예제 #12
0
        /// <summary>
        /// 批量添加标签与分组关联
        /// </summary>
        /// <param name="tagNames">标签名</param>
        /// <param name="groupId">分组Id</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        public int BatchAddTagsInGroup(IEnumerable <string> tagNames, long groupId, string tenantTypeId)
        {
            int affectCount      = 0;
            PetaPocoDatabase dao = CreateDAO();

            dao.OpenSharedConnection();

            dao.Execute(Sql.Builder.Append("delete from tn_TagsInGroups where GroupId = @0", groupId));

            IList <PetaPoco.Sql> sqls = new List <PetaPoco.Sql>();

            foreach (var tagName in tagNames)
            {
                if (string.IsNullOrEmpty(tagName))
                {
                    continue;
                }

                sqls.Add(Sql.Builder.Append("INSERT INTO tn_TagsInGroups (GroupId, TagName,TenantTypeId) VALUES (@0,@1,@2)", groupId, tagName, tenantTypeId));
            }
            affectCount = dao.Execute(sqls);

            if (affectCount > 0)
            {
                RealTimeCacheHelper.IncreaseAreaVersion("GroupId", groupId);
            }

            dao.CloseSharedConnection();

            return(affectCount);
        }
예제 #13
0
        /// <summary>
        /// 创建帖吧
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override object Insert(BarSection entity)
        {
            var sectionId_object = base.Insert(entity);

            //更新用户申请过的帖吧列表缓存
            RealTimeCacheHelper.IncreaseAreaVersion("UserId", entity.UserId);
            return(sectionId_object);
        }
예제 #14
0
        /// <summary>
        /// 移除用户的所有角色
        /// </summary>
        /// <param name="userId">用户Id</param>
        public void RemoveUserRoles(long userId)
        {
            var sqlDelete = Sql.Builder;

            sqlDelete.Append("Delete from tn_UsersInRoles where UserId = @0", userId);
            CreateDAO().Execute(sqlDelete);
            RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
        }
        /// <summary>
        /// 清除呈现区域实例Owner的所有导航
        /// </summary>
        /// <param name="presentAreaKey">呈现区域标识</param>
        /// <param name="ownerId">呈现区域实体OwnerId</param>
        public void ClearOwnerNavigations(string presentAreaKey, long ownerId)
        {
            var sql = PetaPoco.Sql.Builder;

            sql.Append("delete from tn_PresentAreaNavigations where PresentAreaKey = @0 and OwnerId=@1", presentAreaKey, ownerId);
            RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", ownerId);
            CreateDAO().Execute(sql);
        }
예제 #16
0
        /// <summary>
        /// 添加相关标签
        /// </summary>
        /// <remarks>
        /// 会为标签添加双向的关联关系,例如:
        /// TagA关联到TagB
        /// TagB关联到TagA
        /// </remarks>
        /// <param name="tagNames">相关标签名称集合</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="ownerId">拥有者Id</param>
        /// <param name="tagId">标签Id</param>
        /// <returns> 影响行数</returns>
        public int AddRelatedTagsToTag(string[] tagNames, string tenantTypeId, long ownerId, long tagId)
        {
            Database dao = CreateDAO();

            int affectCount = 0;

            dao.OpenSharedConnection();

            foreach (string tagName in tagNames)
            {
                if (string.IsNullOrEmpty(tagName))
                {
                    continue;
                }

                IList <Sql> sqls = new List <Sql>();
                //创建标签
                var sql = Sql.Builder;
                sql.From("tn_Tags")
                .Where("TenantTypeId = @0", tenantTypeId)
                .Where("TagName = @0", tagName);
                var tag = dao.FirstOrDefault <Tag>(sql);
                if (tag == null)
                {
                    sqls.Add(Sql.Builder.Append("insert into tn_Tags (TenantTypeId,TagName,DateCreated,ItemCount,OwnerCount) values (@0,@1,@2,1,1)", tenantTypeId, tagName, DateTime.UtcNow));
                }
                //创建标签与用户的关联
                sql = Sql.Builder;
                sql.From("tn_TagsInOwners")
                .Where("TenantTypeId = @0", tenantTypeId)
                .Where("TagName = @0", tagName)
                .Where("OwnerId = @0", ownerId);
                var tagInOwner = dao.FirstOrDefault <TagInOwner>(sql);
                if (tagInOwner == null)
                {
                    sqls.Add(Sql.Builder.Append("insert into tn_TagsInOwners (TenantTypeId,TagName,OwnerId,ItemCount) values (@0,@1,@2,1)", tenantTypeId, tagName, ownerId));
                }
                //创建标签与内容项的关联
                sqls.Add(Sql.Builder.Append("insert into tn_RelatedTags(TagId, RelatedTagId) select @0,TagId from tn_Tags where TenantTypeId = @1 and TagName = @2", tagId, tenantTypeId, tagName));
                sqls.Add(Sql.Builder.Append("insert into tn_RelatedTags(TagId, RelatedTagId) select TagId,@0 from tn_Tags where TenantTypeId = @1 and TagName = @2", tagId, tenantTypeId, tagName));

                //通过事务来控制多条语句执行时的一致性
                using (var transaction = dao.GetTransaction())
                {
                    affectCount = dao.Execute(sqls);
                    transaction.Complete();
                }
            }

            dao.CloseSharedConnection();

            if (affectCount > 0)
            {
                RealTimeCacheHelper.IncreaseAreaVersion("TagId", tagId);
            }

            return(affectCount);
        }
        /// <summary>
        /// 更新内容隐私设置
        /// </summary>
        /// <param name="privacyable">可隐私接口</param>
        /// <param name="specifyObjects"><remarks>key=specifyObjectTypeId,value=内容指定对象集合</remarks></param>
        public void UpdatePrivacySettings(IPrivacyable privacyable, Dictionary <int, IEnumerable <ContentPrivacySpecifyObject> > specifyObjects)
        {
            //回复:已修改
            var sql = Sql.Builder;
            //List<ContentPrivacySpecifyObject> userPrivacySpecifyObjects;
            //IEnumerable<ContentPrivacySpecifyObject> pairs;
            //IEnumerable<ContentPrivacySpecifyObject> deletePairs;
            //IEnumerable<ContentPrivacySpecifyObject> insertPairs;

            Database dao = CreateDAO();

            dao.OpenSharedConnection();

            sql.Append("delete from tn_ContentPrivacySpecifyObjects")
            .Where("ContentId = @0", privacyable.ContentId)
            .Where("TenantTypeId = @0", privacyable.TenantTypeId);
            dao.Execute(sql);

            if (specifyObjects == null)
            {
                specifyObjects = new Dictionary <int, IEnumerable <ContentPrivacySpecifyObject> >();
            }

            foreach (var item in specifyObjects)
            {
                //sql = Sql.Builder;
                //done:zhangp,by zhengw:SpecifyObjectId=>SpecifyObjectTypeId
                //回复:已修改


                foreach (var insertPair in item.Value)
                {
                    dao.Insert(insertPair);
                }

                //sql.Select("*")
                //   .From("tn_ContentPrivacySpecifyObjects")
                //   .Where("ContentId = @0", privacyable.ContentId)
                //   .Where("TenantTypeId = @0", privacyable.TenantTypeId)
                //   .Where("SpecifyObjectTypeId = @0", item.Key);

                //userPrivacySpecifyObjects = dao.Fetch<ContentPrivacySpecifyObject>(sql);

                //done:zhangp,by zhengw:userPrivacySpecifyObjects.Count为0时就不更新了?我觉得可以把这个判断去掉,两个边界情况都可以使用求交集的办法
                //回复:已修改

                //pairs = userPrivacySpecifyObjects.Intersect(item.Value);
                //deletePairs = userPrivacySpecifyObjects.Except(pairs);
                //foreach (var deletePair in deletePairs)
                //    dao.Delete(deletePair);
                //insertPairs = item.Value.Except(pairs);
                //foreach (var insertPair in insertPairs)
                //    dao.Insert(insertPair);
            }

            dao.CloseSharedConnection();
            RealTimeCacheHelper.IncreaseAreaVersion("TenantTypeId", privacyable.TenantTypeId);
        }
예제 #18
0
        /// <summary>
        /// 清空接受人的通知记录
        /// </summary>
        /// <param name="userId">用户的id</param>
        public void ClearAll(long userId)
        {
            var sql = PetaPoco.Sql.Builder.Append("delete from tn_Invitations where UserId=@0 and Status <> @1", userId, (int)InvitationStatus.Unhandled);

            CreateDAO().Execute(sql);

            //更新列表缓存缓存
            RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
        }
        /// <summary>
        /// 更新实体缓存
        /// </summary>
        /// <param name="rotationImg"></param>
        /// <returns></returns>
        public bool UpdateCacheByEntity(GoodsInRotationImage rotationImg)
        {
            var result = base.UpdateByCache(rotationImg);

            if (result)
            {
                RealTimeCacheHelper.IncreaseAreaVersion("GoodsId", rotationImg.Goodsid);
            }
            return(result);
        }
예제 #20
0
        /// <summary>
        /// 根据角色名称删除角色所拥有的权限项
        /// </summary>
        /// <param name="list"></param>
        /// <param name="rolesName"></param>
        /// <returns></returns>
        public bool DeletePermissionItemsInRolesByRolesname(List <PermissionItemsInRoles> list, string rolesName)
        {
            var result = base.Delete(list);

            if (result)
            {
                RealTimeCacheHelper.IncreaseAreaVersion("Rolename", rolesName);
            }
            return(result);
        }
        /// <summary>
        /// 更新操作
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool UpdataCategoryLevel(GoodsCategoryLevel2 entity, int oldCategoryLevel2Id)
        {
            var result = base.UpdateByCache(entity);

            if (result && oldCategoryLevel2Id > 0 && entity.CategoryLevel1Id != oldCategoryLevel2Id)
            {
                RealTimeCacheHelper.IncreaseAreaVersion("CategoryLevel1Id", oldCategoryLevel2Id);
            }
            return(result);
        }
예제 #22
0
        /// <summary>
        /// 更新实体缓存
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool UpdateCacheByEntity(GoodsInDetailImage entity)
        {
            var result = base.UpdateByCache(entity);

            if (result)
            {
                RealTimeCacheHelper.IncreaseAreaVersion("GoodsId", entity.Goodsid);
            }
            return(result);
        }
예제 #23
0
        /// <summary>
        /// 清空用户隐私设置(用于恢复到默认设置)
        /// </summary>
        /// <param name="userId"></param>
        public void ClearUserPrivacySettings(long userId)
        {
            var sql = Sql.Builder;

            sql.Append("delete from tn_UserPrivacySpecifyObjects where UserPrivacySettingId in (select Id from tn_UserPrivacySettings where UserId = @0)", userId);
            sql.Append("delete from tn_UserPrivacySettings  where UserId = @0", userId);
            CreateDAO().Execute(sql);
            EntityData.ForType(typeof(UserPrivacySpecifyObject)).RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
            RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
        }
예제 #24
0
        /// <summary>
        /// 删除权限项,同时删除所有角色所拥有的该权限项
        /// </summary>
        /// <param name="itemKey"></param>
        /// <returns></returns>
        public bool DeletePermissionItems(PermissionItems entity)
        {
            var result = base.DeleteByCache(entity);

            if (result)
            {
                RealTimeCacheHelper.IncreaseAreaVersion("parentsid", entity.Parentsid);
            }
            return(result);
        }
예제 #25
0
        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool DeleteEntityByCache(GoodsInDetailImage entity)
        {
            var result = base.Delete(m => m.Id == entity.Id);

            if (result)
            {
                OnDeleted(entity);
                RealTimeCacheHelper.IncreaseAreaVersion("GoodsId", entity.Goodsid);
            }
            return(result);
        }
 /// <summary>
 /// 移除用户所有角色
 /// </summary>
 /// <param name="userId">用户编号</param>
 public void RemoveRolesInUser(long userId)
 {
     using (var db = DbService.GetInstance())
     {
         var result = db.ExecuteCommand("delete from sc_users_in_roles where userid = @userid", new { userid = userId });
         if (result > 0)
         {
             RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
         }
     }
 }
예제 #27
0
        /// <summary>
        /// 删除用户的一个角色
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="roleName">角色名</param>
        public void Delete(long userId, string roleName)
        {
            var sql = Sql.Builder;

            sql.Append("delete from tn_UsersInRoles")
            .Where("UserId= @0 and RoleName=@1", userId, roleName);
            CreateDAO().Execute(sql);

            //增加版本
            RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
        }
예제 #28
0
        /// <summary>
        /// 将动态加入到用户动态收件箱
        /// </summary>
        /// <param name="activityId"></param>
        /// <param name="userIds"></param>
        public void InsertUserInboxs(long activityId, IEnumerable <long> userIds)
        {
            if (userIds == null)
            {
                return;
            }

            var activity = Get(activityId);

            if (activity == null)
            {
                return;
            }

            Database dao = CreateDAO();

            dao.OpenSharedConnection();
            Sql         sql;
            List <long> activityIds = new List <long> {
                activityId
            };

            if (activity.ReferenceId > 0)
            {
                sql = Sql.Builder.Select("ActivityId").From("tn_Activities").Where("TenantTypeId=@0", activity.ReferenceTenantTypeId).Where("SourceId=@0", activity.ReferenceId);
                activityIds.AddRange(dao.Fetch <long>(sql).Distinct());
            }

            //若已存在,则不再添加
            List <Sql>  sqls           = new List <Sql>();
            List <long> updatedUserIds = new List <long>();

            foreach (var userId in userIds.Distinct())
            {
                sql = Sql.Builder.Select("count(*)").From("tn_ActivityUserInbox").Where("ActivityId in (@activityIds)", new { activityIds = activityIds }).Where("UserId=@0", userId);
                if (dao.FirstOrDefault <long>(sql) > 0)
                {
                    continue;  //已经存在
                }
                sql = Sql.Builder
                      .Append(@"insert tn_ActivityUserInbox (UserId,ActivityId) values(@0,@1)", userId, activityId);

                sqls.Add(sql);
                updatedUserIds.Add(userId);
            }
            dao.Execute(sqls);
            dao.CloseSharedConnection();

            //更新缓存
            foreach (var userId in updatedUserIds)
            {
                RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
            }
        }
예제 #29
0
        /// <summary>
        /// 把用户加入黑名单
        /// </summary>
        /// <param name="stopedUser">黑名单</param>
        public bool CreateStopedUser(StopedUser stopedUser)
        {
            Dictionary <long, StopedUser> stopUsers = GetStopedUsers(stopedUser.UserId);

            if (stopUsers != null && stopUsers.Count() > new PrivacySettings().StopUserMaxCount)
            {
                return(false);
            }
            Insert(stopedUser);
            RealTimeCacheHelper.IncreaseAreaVersion("UserId", stopedUser.UserId);
            return(true);
        }
예제 #30
0
        /// <summary>
        /// 从用户动态收件箱移除OwnerId的所有动态
        /// </summary>
        /// <remarks>
        /// 取消关注/退出群组、屏蔽用户/屏蔽群组时使用
        /// </remarks>
        /// <param name="userId">UserId</param>
        /// <param name="ownerType">动态拥有者类型</param>
        /// <param name="ownerId">动态拥有者Id</param>
        public void RemoveInboxAboutOwner(long userId, long ownerId, int ownerType)
        {
            //缓存需要即时
            Sql sql = Sql.Builder
                      .Append(@"delete from tn_ActivityUserInbox where ActivityId in 
                            (select ActivityId from tn_Activities where OwnerId=@0 and  OwnerType=@1 ) ", ownerId, ownerType);
            int affectCount = CreateDAO().Execute(sql);

            if (affectCount > 0)
            {
                RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
            }
        }