示例#1
0
        public List <SiteMenusInfo> GetMenusAccess(Guid appId, Guid accessId, bool isAdministrators)
        {
            var list   = new List <SiteMenusInfo>();
            var maInfo = new SiteMenusAccess().GetModel(appId, accessId);
            List <SiteMenusAccessItemInfo> maitems = null;

            if (maInfo != null)
            {
                maitems = JsonConvert.DeserializeObject <List <SiteMenusAccessItemInfo> >(maInfo.OperationAccess);
            }

            var cmdText = "select m.Id,m.ParentId,m.Title,m.Url,m.Descr from SiteMenus m where m.ApplicationId = @ApplicationId ";
            var parm    = new SqlParameter("@ApplicationId", appId);

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.AspnetDbConnString, CommandType.Text, cmdText, parm))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        var model = new SiteMenusInfo();
                        model.Id       = reader.GetGuid(0);
                        model.ParentId = reader.GetGuid(1);
                        model.Title    = reader.GetString(2);
                        model.Url      = reader.GetString(3);
                        model.Descr    = reader.GetString(4);

                        if (isAdministrators)
                        {
                            model.IsView   = true;
                            model.IsAdd    = true;
                            model.IsEdit   = true;
                            model.IsDelete = true;
                        }
                        else
                        {
                            if (maitems != null)
                            {
                                var maitemInfo = maitems.FirstOrDefault(m => Guid.Parse(m.MenuId.ToString()).Equals(model.Id));
                                model.IsView   = maitemInfo == null ? false : maitemInfo.IsView;
                                model.IsAdd    = maitemInfo == null ? false : maitemInfo.IsAdd;
                                model.IsEdit   = maitemInfo == null ? false : maitemInfo.IsEdit;
                                model.IsDelete = maitemInfo == null ? false : maitemInfo.IsDelete;
                            }
                        }

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
示例#2
0
        public IList <SiteMenusInfo> GetMenusAccess(string appName, string[] accessIds, bool isAdministrators)
        {
            var list  = new List <SiteMenusInfo>();
            var appId = new Applications().GetAspnetAppId(appName);
            IList <SiteMenusAccessInfo> maList = null;

            if (!isAdministrators)
            {
                var sbIn = new StringBuilder(300);
                foreach (var item in accessIds)
                {
                    sbIn.AppendFormat("'{0}',", item);
                }
                var sqlWhere = string.Format("and ApplicationId = '{1}' and AccessId in ({0}) ", sbIn.ToString().Trim(','), appId);
                maList = new SiteMenusAccess().GetList(sqlWhere, null);
            }

            var cmdText = "select m.Id,m.ParentId,m.Title,m.Url,m.Descr from SiteMenus m where m.ApplicationId = @ApplicationId order by Sort ";
            var parm    = new SqlParameter("@ApplicationId", appId);

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.AspnetDbConnString, CommandType.Text, cmdText, parm))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        var model = new SiteMenusInfo();
                        model.Id       = reader.GetGuid(0);
                        model.ParentId = reader.GetGuid(1);
                        model.Title    = reader.GetString(2);
                        model.Url      = reader.GetString(3);
                        model.Descr    = reader.GetString(4);

                        if (isAdministrators)
                        {
                            model.IsView   = true;
                            model.IsAdd    = true;
                            model.IsEdit   = true;
                            model.IsDelete = true;
                        }
                        else
                        {
                            #region 权限控制

                            if (maList != null && maList.Count > 0)
                            {
                                List <SiteMenusAccessItemInfo> maitems = null;

                                var qrmaList = maList.Where(m => m.AccessType == "Roles");
                                if (qrmaList != null && qrmaList.Count() > 0)
                                {
                                    foreach (var item in qrmaList)
                                    {
                                        maitems = JsonConvert.DeserializeObject <List <SiteMenusAccessItemInfo> >(item.OperationAccess);
                                        var maitemInfo = maitems.FirstOrDefault(m => Guid.Parse(m.MenuId.ToString()).Equals(model.Id));
                                        model.IsView   = maitemInfo == null ? false : maitemInfo.IsView;
                                        model.IsAdd    = maitemInfo == null ? false : maitemInfo.IsAdd;
                                        model.IsEdit   = maitemInfo == null ? false : maitemInfo.IsEdit;
                                        model.IsDelete = maitemInfo == null ? false : maitemInfo.IsDelete;
                                    }
                                }

                                var qumaInfo = maList.FirstOrDefault(m => m.AccessType == "Users");
                                if (qumaInfo != null)
                                {
                                    maitems = JsonConvert.DeserializeObject <List <SiteMenusAccessItemInfo> >(qumaInfo.OperationAccess);
                                    var maitemInfo = maitems.FirstOrDefault(m => Guid.Parse(m.MenuId.ToString()).Equals(model.Id));
                                    if (maitemInfo != null)
                                    {
                                        if (maitemInfo.IsView)
                                        {
                                            model.IsView = false;
                                        }
                                        if (maitemInfo.IsAdd)
                                        {
                                            model.IsAdd = false;
                                        }
                                        if (maitemInfo.IsEdit)
                                        {
                                            model.IsEdit = false;
                                        }
                                        if (maitemInfo.IsDelete)
                                        {
                                            model.IsDelete = false;
                                        }
                                    }
                                }
                            }

                            #endregion
                        }

                        if (model.IsView)
                        {
                            list.Add(model);
                        }
                    }
                }
            }

            return(list);
        }