Example #1
0
        /// <summary>
        /// 设置默认成员
        /// </summary>
        /// <param name="memberID"></param>
        /// <param name="userID"></param>
        /// <returns></returns>
        public bool SetDefaultMember(string memberID, string userID)
        {
            using (var db = new DBEntities())
            {
                using (db.BeginTransaction())
                {
                    db.UserMembers.Where(a => a.UserID == userID && a.MemberID != memberID).Update(a => new UserMember()
                    {
                        IsDefault    = false,
                        ModifyTime   = DateTime.Now,
                        ModifyUserID = userID
                    });

                    db.UserMembers.Where(a => a.UserID == userID && a.MemberID == memberID).Update(a => new UserMember()
                    {
                        IsDefault    = true,
                        ModifyTime   = DateTime.Now,
                        ModifyUserID = userID
                    });

                    db.Commit();
                    var userMemberMapCacheKey = new XuHos.Common.Cache.Keys.EntityListCacheKey <UserMember>(XuHos.Common.Cache.Keys.StringCacheKeyType.User_Member, memberID);
                    userMemberMapCacheKey.RemoveCache();
                }
                return(true);
            }
        }
Example #2
0
        /// <summary>
        /// 加入角色

        /// 日期:2017年8月19日
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="roletype"></param>
        /// <returns></returns>
        public bool JoinRole(string userId, EnumRoleType roletype)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return(false);
            }

            using (var db = new DBEntities())
            {
                var ret      = false;
                var cacheKey = new XuHos.Common.Cache.Keys.EntityListCacheKey <EnumRoleType>(StringCacheKeyType.User_RoleList, userId);
                var rolem    = (from roleMap in db.UserRoleMaps
                                join role in db.UserRoles on roleMap.RoleID equals role.RoleID
                                where roleMap.UserID == userId && role.RoleType == roletype
                                select roleMap).FirstOrDefault();

                //已经存在
                if (rolem != null)
                {
                    #region 修改
                    if (rolem.IsDeleted)
                    {
                        rolem.IsDeleted = false;
                        ret             = db.SaveChanges() > 0;
                    }
                    else
                    {
                        ret = true;
                    }
                    #endregion
                }
                else
                {
                    #region 添加记录
                    var roleid = (from role in db.UserRoles
                                  where role.RoleType == roletype
                                  select role.RoleID).FirstOrDefault();

                    if (!string.IsNullOrEmpty(roleid))
                    {
                        rolem = new Entity.UserRoleMap();
                        rolem.UserRoleMapID = Guid.NewGuid().ToString("N");
                        rolem.RoleID        = roleid;
                        rolem.UserID        = userId;
                        db.UserRoleMaps.Add(rolem);
                        ret = db.SaveChanges() > 0;
                    }
                    #endregion
                }

                #region  除缓存
                if (ret)
                {
                    cacheKey.RemoveCache();
                }
                #endregion

                return(ret);
            }
        }
Example #3
0
        /// <summary>
        /// 删除成员信息
        /// </summary>
        ///<remarks>
        ///1.有预约记录不能删除
        ///2.本人不能删除
        ///</remarks>
        /// <param name="UserID"></param>
        /// <param name="MemberID"></param>
        /// <returns></returns>
        public EnumApiStatus DeleteMemberInfo(string UserID, string MemberID, string orgid = "kmwlyy")
        {
            using (DBEntities db = new DBEntities())
            {
                //var member = GetMemberInfo(UserID, MemberID);
                db.Configuration.AutoDetectChangesEnabled = true;
                var map = db.UserMembers.Where(q => q.UserID == UserID && q.MemberID == MemberID && q.IsDeleted == false).FirstOrDefault();
                if (map == null)
                {
                    throw new Exception($"没找到关联关系:(UserID:{UserID},MemberID:{MemberID})");
                }
                //不允许删除本人
                if (map.Relation == EnumUserRelation.MySelf)
                {
                    return(EnumApiStatus.BizUserMemberRejectDeleteMySelf);
                }

                if (orgid != null && orgid.ToLower() != "jkfwz" && orgid.ToLower() != "kmsd")
                {
                    var orderCount = db.UserOpdRegisters.Count(a => a.UserID == UserID && a.MemberID == MemberID && !a.IsDeleted);

                    if (orderCount > 0)
                    {
                        return(EnumApiStatus.BizUserMemberRejectDeleteHasRelationOrder);
                    }
                }

                map.IsDeleted    = true;
                map.DeleteTime   = DateTime.Now;
                map.DeleteUserID = UserID;

                if (db.SaveChanges() > 0)
                {
                    var userMemberMapCacheKey = new XuHos.Common.Cache.Keys.EntityListCacheKey <UserMember>(XuHos.Common.Cache.Keys.StringCacheKeyType.User_Member, MemberID);
                    userMemberMapCacheKey.RemoveCache();

                    return(EnumApiStatus.BizOK);
                }
                else
                {
                    return(EnumApiStatus.BizError);
                }
            }
        }