Exemple #1
0
        public override void DoAdd()
        {
            if (Entity.IsInside == true)
            {
                var             domain = DC.Set <FrameworkDomain>().Where(x => x.ID == Entity.DomainId).FirstOrDefault();
                FrameworkAction act    = null;
                if (domain == null)
                {
                    act = DC.Set <FrameworkAction>().Include(x => x.Module.Area).Where(x => x.ID == Entity.ActionId).FirstOrDefault();
                }
                else
                {
                    act = APIHelper.CallAPI <FrameworkAction>(domain.Address + "/WebApi/Pub/GetAction?id=" + Entity.ActionId + "&domainid=" + Entity.DomainId + "&eventts=" + DateTime.Now.Ticks).Result;
                }
                if (act != null)
                {
                    Entity.Url = "/" + act.Module.ClassName + "/" + act.MethodName;
                    if (act.Module.Area != null)
                    {
                        Entity.Url = "/" + act.Module.Area.Prefix + Entity.Url;
                    }
                    Entity.ModuleName = act.Module.ModuleName;
                    Entity.ActionName = act.ActionName;
                }
            }
            else
            {
                Entity.ActionId = null;
                Entity.ModuleId = null;
                if (Entity.Url != null && Entity.Url != "")
                {
                    if (Entity.DomainId == null)
                    {
                        if (Entity.Url.ToLower().StartsWith("http://") == false)
                        {
                            Entity.Url = "http://" + Entity.Url;
                        }
                    }
                    else
                    {
                        if (Entity.Url.StartsWith("/") == false)
                        {
                            Entity.Url = "/" + Entity.Url;
                        }
                    }
                }
            }
            var role = DC.Set <FrameworkRole>().Where(x => x.RoleCode == "001").SingleOrDefault();

            if (role != null && SelectedRolesIDs.Contains(role.ID) == false && SelectedRolesID2.Contains(role.ID) == false)
            {
                Entity.Privileges.Add(new FunctionPrivilege {
                    RoleId = role.ID, Allowed = true
                });
            }
            base.DoAdd();
            AddPrivilege(Entity.ID);
        }
Exemple #2
0
        public void AddPrivilege(List <Guid> menuids)
        {
            var oldIDs = DC.Set <FunctionPrivilege>().Where(x => menuids.Contains(x.MenuItemId)).Select(x => x.ID).ToList();
            var admin  = DC.Set <FrameworkRole>().Where(x => x.RoleCode == "001").SingleOrDefault();

            foreach (var oldid in oldIDs)
            {
                try
                {
                    FunctionPrivilege fp = new FunctionPrivilege {
                        ID = oldid
                    };
                    DC.Set <FunctionPrivilege>().Attach(fp);
                    DC.DeleteEntity(fp);
                }
                catch { }
            }
            if (admin != null && SelectedRolesIDs.Contains(admin.ID) == false)
            {
                SelectedRolesIDs.Add(admin.ID);
            }
            foreach (var menuid in menuids)
            {
                if (SelectedRolesIDs != null)
                {
                    foreach (var id in SelectedRolesIDs)
                    {
                        FunctionPrivilege fp = new FunctionPrivilege();
                        fp.MenuItemId = menuid;
                        fp.RoleId     = id;
                        fp.UserId     = null;
                        fp.Allowed    = true;
                        DC.Set <FunctionPrivilege>().Add(fp);
                    }
                }
            }

            DC.SaveChanges();
        }
Exemple #3
0
        public void DoBatchAdd()
        {
            var role = DC.Set <FrameworkRole>().Where(x => x.RoleCode == "001").SingleOrDefault();

            if (role != null && SelectedRolesIDs.Contains(role.ID) == false && SelectedRolesID2.Contains(role.ID) == false)
            {
                Entity.Privileges.Add(new FunctionPrivilege {
                    RoleId = role.ID, Allowed = true
                });
            }
            if (Entity.ModuleId != null && Entity.ActionId != null)
            {
                var domain = DC.Set <FrameworkDomain>().Where(x => x.ID == Entity.DomainId).FirstOrDefault();
                List <FrameworkAction> otherActions = null;
                FrameworkAction        act          = null;
                if (domain == null)
                {
                    act          = DC.Set <FrameworkAction>().Include(x => x.Module.Area).Where(x => x.ID == Entity.ActionId).FirstOrDefault();
                    otherActions = DC.Set <FrameworkAction>().Include(x => x.Module.Area).Where(x => x.ModuleId == this.Entity.ModuleId && x.ID != Entity.ActionId).ToList();
                }
                else
                {
                    otherActions = APIHelper.CallAPI <List <FrameworkAction> >(domain.Address + "/WebApi/Pub/GetOtherActions?id=" + Entity.ActionId + "&moduleid=" + Entity.ModuleId + "&eventts=" + DateTime.Now.Ticks).Result;
                    act          = APIHelper.CallAPI <FrameworkAction>(domain.Address + "/WebApi/Pub/GetAction?id=" + Entity.ActionId + "&domainid=" + Entity.DomainId + "&eventts=" + DateTime.Now.Ticks).Result;
                }
                if (act != null)
                {
                    Entity.Url = "/" + act.Module.ClassName + "/" + act.MethodName;
                    if (act.Module.Area != null)
                    {
                        Entity.Url = "/" + act.Module.Area.Prefix + Entity.Url;
                    }
                    Entity.ModuleName = act.Module.ModuleName;
                    Entity.ActionName = act.ActionName;
                }
                int order = 1;
                foreach (var action in otherActions)
                {
                    FrameworkMenu menu = new FrameworkMenu();
                    menu.ActionId     = action.ID;
                    menu.ModuleId     = action.ModuleId;
                    menu.FolderOnly   = false;
                    menu.IsPublic     = false;
                    menu.Parent       = Entity;
                    menu.ShowOnMenu   = false;
                    menu.DisplayOrder = order++;
                    menu.Privileges   = new List <FunctionPrivilege>();
                    menu.CreateBy     = LoginUserInfo.ITCode;
                    menu.CreateTime   = DateTime.Now;
                    menu.IsInside     = true;
                    menu.DomainId     = Entity.DomainId;
                    if (role != null)
                    {
                        menu.Privileges.Add(new FunctionPrivilege {
                            RoleId = role.ID, Allowed = true
                        });
                    }
                    menu.PageName   = action.ActionName;
                    menu.ModuleName = action.Module.ModuleName;
                    menu.ActionName = action.ActionName;
                    menu.Url        = "/" + action.Module.ClassName + "/" + action.MethodName;
                    if (action.Module.Area != null)
                    {
                        menu.Url = "/" + action.Module.Area.Prefix + menu.Url;
                    }

                    Entity.Children.Add(menu);
                }
            }
            base.DoAdd();
            AddPrivilege(Entity.ID);
        }