Example #1
0
 /// <summary>
 /// 作者:Vincen
 /// 时间:2013.12.11
 /// 描述:设置(用户权限)缓存
 /// </summary>
 /// <param name="userRights"></param>
 public static void SetUserRightsCache(UserRights userRights)
 {
     if (null == userRights) return;
     if (!Icache.IsSet(string.Format("{0}{1}", Kword, userRights.Id)))
     {
         Icache.Set(string.Format("{0}{1}", Kword, userRights.Id), userRights, 180 * 24 * 60);
     }
 }
Example #2
0
        /// <summary>
        /// 作者:Vincen
        /// 时间:2014.04.22
        /// 描述:更新用户权限
        /// 作者:Primo
        /// 时间:2014.05.31
        /// 描述:更新用户权限,差异更改
        /// ---------------------
        /// 描述:更新使用新的Context实列
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="rightsList">
        /// 格式:1-2-3
        /// </param>
        /// <param name="loginUserId"></param>
        /// <returns></returns>
        public static bool UpdateUserRights(int userId, string rightsList, int loginUserId)
        {
            using (var edb = new EmeEntities())
            {
                try
                {
                    // Step1、修改和附加新权限
                    var strList = rightsList.Trim('-').Split('-').ToList();
                    foreach (var item in strList)
                    {
                        if (item == "" || item == "-")
                            continue;

                        //查看是不是在使用状态,如果是,直接置为不可用
                        var intItem = CommonHelper.To<int>(item);
                        if (edb.UserRights.Any(p => p.UserId == userId && p.RightsId == intItem && p.Status == ConvertEnum.StatusTypeForActive))
                        {
                            var userRights = edb.UserRights.FirstOrDefault(p => p.UserId == userId && p.RightsId == intItem && p.Status == ConvertEnum.StatusTypeForActive);
                            if (userRights != null)
                            {
                                edb.Entry(userRights).State = EntityState.Deleted;

                                //删除页面模块
                                var umModelObj = edb.UserModule.Where(a => a.UserId == userId && a.RightsId == userRights.RightsId);
                                foreach (var umModel in umModelObj)
                                {
                                    edb.Entry(umModel).State = EntityState.Deleted;
                                }

                                //删除快捷入口
                                var modelUserShortcut = edb.UserShortcut.Where(a => a.UserId == userId && a.RightsId == userRights.RightsId);
                                foreach (var usModel in modelUserShortcut)
                                {
                                    edb.Entry(usModel).State = EntityState.Deleted;
                                }
                            }
                        }
                        //查看是不是失效状态,如果是,直接置为可用
                        else
                        {
                            var userRights = edb.UserRights.SingleOrDefault(p => p.UserId == userId && p.RightsId == intItem);
                            if (userRights != null)
                            {
                                userRights.Status = ConvertEnum.StatusTypeForActive;
                                userRights.UpdateTime = DateTime.Now;
                                edb.Entry(userRights).State = EntityState.Modified;
                            }
                            else
                            {
                                var model = new UserRights()
                                {
                                    UserId = userId,
                                    RightsId = CommonHelper.To<int>(intItem),
                                    Status = ConvertEnum.StatusTypeForActive,
                                    CreateTime = DateTime.Now
                                };
                                edb.Entry(model).State = EntityState.Added;
                            }
                        }
                    }

                    // Step2、标准自定义权限标签
                    var user = edb.User.SingleOrDefault(p => p.Id == userId);
                    if (null != user)
                    {
                        user.IsOverwriteRights = true;
                        user.UpdateTime = DateTime.Now;

                        edb.Entry(user).State = EntityState.Modified;
                    }

                    var result = edb.SaveChanges() > 0;

                    return result;
                }
                catch (Exception ex)
                {
                    Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs()
                    {
                        ExceptionType = CommonHelper.To<int>(ExceptionType.Message),
                        Message = string.Format("UserBLL-UpdateUserRights:{0};{1};{2}", ex.Message, ex.InnerException, ex.HelpLink),
                        IsTreat = false,
                        CreateBy = loginUserId,
                        CreateTime = DateTime.Now
                    });
                }

                return false;
            }
        }
Example #3
0
 /// <summary>
 /// 作者:Vincen
 /// 时间:2013.12.11
 /// 描述:更新(用户权限)缓存
 /// </summary>
 /// <param name="userRights"></param>
 public static void UpdateUserRightsCache(UserRights userRights)
 {
     Icache.Set(string.Format("{0}{1}", Kword, userRights.Id), userRights, 180 * 24 * 60);
 }