Пример #1
0
        public override void DoEdit(bool updateAllFields = false)
        {
            if (Entity.IsInside == false)
            {
                if (Entity.Url != null && Entity.Url != "")
                {
                    if (string.IsNullOrEmpty(Entity.Domain) == true)
                    {
                        if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.ToLower().StartsWith("https://") == false && Entity.Url.StartsWith("@") == false)
                        {
                            Entity.Url = "http://" + Entity.Url;
                        }
                    }
                    else
                    {
                        if (Entity.Url.StartsWith("/") == false)
                        {
                            Entity.Url = "/" + Entity.Url;
                        }
                    }
                }
            }
            else
            {
                if (string.IsNullOrEmpty(SelectedModule) == true && Entity.FolderOnly == false)
                {
                    MSD.AddModelError("SelectedModule", Localizer["_Admin.SelectModule"]);
                    return;
                }

                if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
                {
                    var modules     = Wtm.GlobaInfo.AllModule;
                    var ndc         = DC.ReCreate();
                    var actionsInDB = DC.Set <FrameworkMenu>().AsNoTracking().Where(x => x.ParentId == Entity.ID).ToList();
                    var mo          = modules.Where(x => x.FullName == this.SelectedModule && x.IsApi == true).FirstOrDefault();
                    Entity.ModuleName = mo.ModuleName;
                    Entity.ClassName  = mo.FullName;
                    Entity.MethodName = null;

                    var otherActions = mo.Actions;
                    int order        = 1;
                    Entity.Children = new List <FrameworkMenu>();
                    foreach (var action in otherActions)
                    {
                        if (SelectedActionIDs != null && SelectedActionIDs.Contains(action.MethodName))
                        {
                            Guid aid = action.ID;
                            var  adb = actionsInDB.Where(x => x.Url.ToLower() == action.Url.ToLower()).FirstOrDefault();
                            if (adb != null)
                            {
                                aid = adb.ID;
                            }
                            FrameworkMenu menu = new FrameworkMenu();
                            menu.FolderOnly   = false;
                            menu.IsPublic     = false;
                            menu.Parent       = Entity;
                            menu.ShowOnMenu   = false;
                            menu.DisplayOrder = order++;
                            menu.Privileges   = new List <FunctionPrivilege>();
                            menu.IsInside     = true;
                            menu.Domain       = Entity.Domain;
                            menu.PageName     = action.ActionDes?.Description ?? action.ActionName;
                            menu.ModuleName   = action.Module.ModuleName;
                            menu.ActionName   = action.ActionDes?.Description ?? action.ActionName;
                            menu.Url          = action.Url;
                            menu.ClassName    = action.Module.FullName;
                            menu.MethodName   = action.MethodName;
                            menu.ID           = aid;
                            Entity.Children.Add(menu);
                        }
                    }
                }

                else
                {
                    Entity.Children = null;
                    Entity.Url      = null;
                }
            }
            if (FC.ContainsKey("Entity.Children") == false)
            {
                FC.Add("Entity.Children", 0);
            }
            base.DoEdit(updateAllFields);
            List <Guid> guids = new List <Guid>();

            guids.Add(Entity.ID);
            if (Entity.Children != null)
            {
                guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
            }
            AddPrivilege(guids);
        }
Пример #2
0
        public override void DoAdd()
        {
            if (Entity.IsInside == false)
            {
                if (Entity.Url != null && Entity.Url != "")
                {
                    if (Entity.DomainId == null)
                    {
                        if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.ToLower().StartsWith("https://") == false && Entity.Url.StartsWith("@") == false)
                        {
                            Entity.Url = "http://" + Entity.Url;
                        }
                    }
                    else
                    {
                        if (Entity.Url.StartsWith("/") == false)
                        {
                            Entity.Url = "/" + Entity.Url;
                        }
                    }
                }
            }
            else
            {
                if (string.IsNullOrEmpty(SelectedModule) == true && Entity.FolderOnly == false)
                {
                    MSD.AddModelError("SelectedModule", Program._localizer["SelectModule"]);
                    return;
                }
                if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
                {
                    var modules = GlobalServices.GetRequiredService <GlobalData>().AllModule;

                    var mo = modules.Where(x => x.FullName == this.SelectedModule && x.IsApi == true).FirstOrDefault();
                    Entity.ModuleName = mo.ModuleName;
                    Entity.ClassName  = mo.FullName;
                    Entity.MethodName = null;

                    var otherActions = mo.Actions;
                    int order        = 1;
                    Entity.Children = new List <FrameworkMenu>();
                    foreach (var action in otherActions)
                    {
                        if (SelectedActionIDs != null && SelectedActionIDs.Contains(action.MethodName))
                        {
                            FrameworkMenu menu = new FrameworkMenu();
                            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;
                            menu.PageName     = action.ActionName;
                            menu.ModuleName   = action.Module.ModuleName;
                            menu.ActionName   = action.ActionName;
                            menu.Url          = action.Url;
                            menu.ClassName    = action.Module.FullName;
                            menu.MethodName   = action.MethodName;
                            Entity.Children.Add(menu);
                        }
                    }
                }

                else
                {
                    Entity.Children = null;
                    Entity.Url      = null;
                }
            }
            base.DoAdd();
            List <Guid> guids = new List <Guid>();

            guids.Add(Entity.ID);
            if (Entity.Children != null)
            {
                guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
            }
            AddPrivilege(guids);
        }
Пример #3
0
        public override void DoAdd()
        {
            Entity.Icon = $"{IconFont} {IconFontItem}";
            if (Entity.IsInside == false)
            {
                if (Entity.Url != null && Entity.Url != "" && Entity.Url.StartsWith("/") == false)
                {
                    if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.ToLower().StartsWith("https://") == false)
                    {
                        Entity.Url = "http://" + Entity.Url;
                    }
                }
            }
            else
            {
                if (string.IsNullOrEmpty(SelectedModule) == true && Entity.FolderOnly == false)
                {
                    MSD.AddModelError("SelectedModule", Localizer["_Admin.SelectModule"]);
                    return;
                }
                if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
                {
                    var modules = Wtm.GlobaInfo.AllModule;
                    List <SimpleAction> otherActions = null;
                    var mainAction = modules.Where(x => x.FullName == this.SelectedModule).SelectMany(x => x.Actions).Where(x => x.MethodName == "Index").FirstOrDefault();
                    if (mainAction == null && Entity.ShowOnMenu == true)
                    {
                        MSD.AddModelError("Entity.ModuleId", Localizer["_Admin.NoIndexInModule"]);
                        return;
                    }
                    if (mainAction == null && Entity.ShowOnMenu == false)
                    {
                        var model = modules.Where(x => x.FullName == this.SelectedModule).FirstOrDefault();
                        mainAction            = new SimpleAction();
                        mainAction.Module     = model;
                        mainAction.MethodName = null;
                    }
                    Entity.Url        = mainAction.Url;
                    Entity.ModuleName = mainAction.Module.ModuleName;
                    Entity.ActionName = mainAction.ActionDes?.Description ?? mainAction.ActionName;
                    Entity.ClassName  = mainAction.Module.FullName;
                    Entity.MethodName = null;
                    Entity.Children   = new List <FrameworkMenu>();

                    otherActions = modules.Where(x => x.FullName == this.SelectedModule).SelectMany(x => x.Actions).Where(x => x.MethodName != "Index").ToList();
                    int order = 1;
                    foreach (var action in otherActions)
                    {
                        if (SelectedActionIDs?.Contains(action.Url) == true)
                        {
                            FrameworkMenu menu = new FrameworkMenu();
                            menu.FolderOnly   = false;
                            menu.IsPublic     = false;
                            menu.Parent       = Entity;
                            menu.ShowOnMenu   = false;
                            menu.DisplayOrder = order++;
                            menu.Privileges   = new List <FunctionPrivilege>();
                            menu.IsInside     = true;
                            menu.Domain       = Entity.Domain;
                            menu.PageName     = action.ActionDes?.Description ?? action.ActionName;
                            menu.ModuleName   = action.Module.ModuleName;
                            menu.ActionName   = action.ActionDes?.Description ?? action.ActionName;
                            menu.ClassName    = action.Module.FullName;
                            menu.MethodName   = action.MethodName;
                            menu.Url          = action.Url;
                            Entity.Children.Add(menu);
                        }
                    }
                }

                else
                {
                    Entity.Children = null;
                    Entity.Url      = null;
                }
            }
            base.DoAdd();
            List <Guid> guids = new List <Guid>();

            guids.Add(Entity.ID);
            if (Entity.Children != null)
            {
                guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
            }
            AddPrivilege(guids);
        }
Пример #4
0
        public override void DoEdit(bool updateAllFields = false)
        {
            Entity.ICon = $"{IconFont} {IconFontItem}";
            FC.Add("Entity.ICon", " ");
            if (Entity.IsInside == false)
            {
                if (Entity.Url != null && Entity.Url != "")
                {
                    if (Entity.DomainId == null)
                    {
                        if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.ToLower().StartsWith("https://") == false)
                        {
                            Entity.Url = "http://" + Entity.Url;
                        }
                    }
                    else
                    {
                        if (Entity.Url.StartsWith("/") == false)
                        {
                            Entity.Url = "/" + Entity.Url;
                        }
                    }
                }
            }
            else
            {
                if (string.IsNullOrEmpty(SelectedModule) == true && Entity.FolderOnly == false)
                {
                    MSD.AddModelError("SelectedModule", Program._localizer["SelectModule"]);
                    return;
                }
                if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
                {
                    var modules = GlobalServices.GetRequiredService <GlobalData>().AllModule;
                    List <FrameworkAction> otherActions = null;
                    var mainAction = modules.Where(x => x.ClassName == this.SelectedModule).SelectMany(x => x.Actions).Where(x => x.MethodName == "Index").SingleOrDefault();
                    if (mainAction == null && Entity.ShowOnMenu == true)
                    {
                        MSD.AddModelError("Entity.ModuleId", Program._localizer["NoIndexInModule"]);
                        return;
                    }
                    if (mainAction == null && Entity.ShowOnMenu == false)
                    {
                        var model = modules.Where(x => x.ClassName == this.SelectedModule)
                                    .FirstOrDefault();
                        mainAction            = new FrameworkAction();
                        mainAction.Module     = model;
                        mainAction.MethodName = null;
                    }

                    Entity.Url        = mainAction.Url;
                    Entity.ModuleName = mainAction.Module.ModuleName;
                    Entity.ActionName = mainAction.ActionName;
                    Entity.ClassName  = mainAction.Module.ClassName;
                    Entity.MethodName = null;

                    otherActions = modules.Where(x => x.ClassName == this.SelectedModule)
                                   .SelectMany(x => x.Actions)
                                   .Where(x => x.MethodName != "Index")
                                   .ToList();
                    var actionsInDB = DC.Set <FrameworkMenu>().AsNoTracking().Where(x => x.ParentId == Entity.ID).ToList();
                    int order       = 1;
                    Entity.Children = new List <FrameworkMenu>();
                    foreach (var action in otherActions)
                    {
                        if (SelectedActionIDs != null && SelectedActionIDs.Contains(action.Url))
                        {
                            Guid aid = action.ID;
                            var  adb = actionsInDB.Where(x => x.Url.ToLower() == action.Url.ToLower()).FirstOrDefault();
                            if (adb != null)
                            {
                                aid = adb.ID;
                            }
                            var menu = new FrameworkMenu();
                            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;
                            menu.PageName     = action.ActionName;
                            menu.ModuleName   = action.Module.ModuleName;
                            menu.ActionName   = action.ActionName;
                            menu.ClassName    = action.Module.ClassName;
                            menu.MethodName   = action.MethodName;
                            menu.Url          = action.Url;
                            menu.ID           = aid;
                            Entity.Children.Add(menu);
                        }
                    }
                }
                else
                {
                    Entity.Children = null;
                    Entity.Url      = null;
                }
            }
            base.DoEdit();
            List <Guid> guids = new List <Guid>();

            guids.Add(Entity.ID);
            if (Entity.Children != null)
            {
                guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
            }
            AddPrivilege(guids);
        }
Пример #5
0
        public override void DoEdit(bool updateAllFields = false)
        {
            Entity.Icon = $"{IconFont} {IconFontItem}";
            FC.Add("Entity.Icon", " ");
            List <Guid> guids = new List <Guid>();

            if (Entity.IsInside == false)
            {
                if (Entity.Url != null && Entity.Url != "" && Entity.Url.StartsWith("/") == false)
                {
                    if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.ToLower().StartsWith("https://") == false)
                    {
                        Entity.Url = "http://" + Entity.Url;
                    }
                }
            }
            else
            {
                if (string.IsNullOrEmpty(SelectedModule) == true && Entity.FolderOnly == false)
                {
                    MSD.AddModelError("SelectedModule", Localizer["_Admin.SelectModule"]);
                    return;
                }
                if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
                {
                    var modules = Wtm.GlobaInfo.AllModule;
                    List <SimpleAction> otherActions = null;
                    var mainAction = modules.Where(x => x.FullName == this.SelectedModule).SelectMany(x => x.Actions).Where(x => x.MethodName == "Index").FirstOrDefault();
                    if (mainAction == null && Entity.ShowOnMenu == true)
                    {
                        MSD.AddModelError("Entity.ModuleId", Localizer["_Admin.NoIndexInModule"]);
                        return;
                    }
                    if (mainAction == null && Entity.ShowOnMenu == false)
                    {
                        var model = modules.Where(x => x.FullName == this.SelectedModule)
                                    .FirstOrDefault();
                        mainAction            = new SimpleAction();
                        mainAction.Module     = model;
                        mainAction.MethodName = null;
                    }

                    Entity.Url        = mainAction.Url;
                    Entity.ModuleName = mainAction.Module.ModuleName;
                    Entity.ActionName = mainAction.ActionDes?.Description ?? mainAction.ActionName;
                    Entity.ClassName  = mainAction.Module.FullName;
                    Entity.MethodName = null;

                    otherActions = modules.Where(x => x.FullName == this.SelectedModule)
                                   .SelectMany(x => x.Actions)
                                   .Where(x => x.MethodName != "Index")
                                   .ToList();
                    var actionsInDB = DC.Set <FrameworkMenu>().AsNoTracking().Where(x => x.ParentId == Entity.ID).ToList();
                    int order       = 1;
                    Entity.Children = new List <FrameworkMenu>();
                    foreach (var action in otherActions)
                    {
                        if (SelectedActionIDs != null && SelectedActionIDs.Contains(action.Url))
                        {
                            Guid aid = action.ID;
                            var  adb = actionsInDB.Where(x => x.Url.ToLower() == action.Url.ToLower()).FirstOrDefault();
                            if (adb != null)
                            {
                                aid = adb.ID;
                            }
                            else
                            {
                                guids.Add(aid);
                            }
                            var menu = new FrameworkMenu();
                            menu.FolderOnly   = false;
                            menu.IsPublic     = false;
                            menu.Parent       = Entity;
                            menu.ShowOnMenu   = false;
                            menu.DisplayOrder = order++;
                            menu.Privileges   = new List <FunctionPrivilege>();
                            menu.IsInside     = true;
                            menu.Domain       = Entity.Domain;
                            menu.PageName     = action.ActionDes?.Description ?? action.ActionName;
                            menu.ModuleName   = action.Module.ModuleName;
                            menu.ActionName   = action.ActionDes?.Description ?? action.ActionName;
                            menu.ClassName    = action.Module.FullName;
                            menu.MethodName   = action.MethodName;
                            menu.Url          = action.Url;
                            menu.ID           = aid;
                            Entity.Children.Add(menu);
                        }
                    }
                }
                else
                {
                    Entity.Children = null;
                    Entity.Url      = null;
                }
            }
            if (FC.ContainsKey("Entity.Children") == false)
            {
                FC.Add("Entity.Children", 0);
            }
            FC.Add("Entity.ModuleName", 0);
            base.DoEdit();
            AddPrivilege(guids);
        }
Пример #6
0
        public override void DoAdd()
        {
            if (Entity.IsInside == false)
            {
                if (Entity.Url != null && Entity.Url != "")
                {
                    if (string.IsNullOrEmpty(Entity.Domain) == true)
                    {
                        if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.ToLower().StartsWith("https://") == false && Entity.Url.StartsWith("@") == false)
                        {
                            Entity.Url = "http://" + Entity.Url;
                        }
                    }
                    else
                    {
                        if (Entity.Url.StartsWith("/") == false)
                        {
                            Entity.Url = "/" + Entity.Url;
                        }
                    }
                    Entity.Url = Entity.Url.TrimEnd('/');
                }
            }
            else
            {
                if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
                {
                    var modules = Wtm.GlobaInfo.AllModule;

                    var mo = modules.Where(x => x.FullName == this.SelectedModule && x.IsApi == true).FirstOrDefault();
                    if (mo != null)
                    {
                        Entity.ModuleName = mo.ModuleName;
                        Entity.ClassName  = mo.FullName;
                        Entity.MethodName = null;

                        var otherActions = mo.Actions;
                        int order        = 1;
                        Entity.Children = new List <FrameworkMenu>();
                        foreach (var action in otherActions)
                        {
                            if (SelectedActionIDs != null && SelectedActionIDs.Contains(action.MethodName))
                            {
                                FrameworkMenu menu = new FrameworkMenu();
                                menu.FolderOnly   = false;
                                menu.IsPublic     = Entity.IsPublic;
                                menu.Parent       = Entity;
                                menu.ShowOnMenu   = false;
                                menu.DisplayOrder = order++;
                                menu.Privileges   = new List <FunctionPrivilege>();
                                menu.IsInside     = true;
                                menu.Domain       = Entity.Domain;
                                menu.PageName     = action.ActionDes?.Description ?? action.ActionName;
                                menu.ModuleName   = action.Module.ModuleName;
                                menu.ActionName   = action.ActionDes?.Description ?? action.ActionName;
                                menu.Url          = action.Url;
                                menu.ClassName    = action.Module.FullName;
                                menu.MethodName   = action.MethodName;
                                Entity.Children.Add(menu);
                            }
                        }
                    }
                }

                else
                {
                    Entity.Children = null;
                    Entity.Url      = null;
                }
            }
            base.DoAdd();
            List <Guid> guids = new List <Guid>();

            guids.Add(Entity.ID);
            if (Entity.Children != null)
            {
                guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
            }
            AddPrivilege(guids);
        }
Пример #7
0
        public override void DoEdit(bool updateAllFields = false)
        {
            if (Entity.IsInside == false)
            {
                if (Entity.Url != null && Entity.Url != "")
                {
                    if (Entity.DomainId == null)
                    {
                        if (Entity.Url.ToLower().StartsWith("http://") == false && Entity.Url.StartsWith("@") == false)
                        {
                            Entity.Url = "http://" + Entity.Url;
                        }
                    }
                    else
                    {
                        if (Entity.Url.StartsWith("/") == false)
                        {
                            Entity.Url = "/" + Entity.Url;
                        }
                    }
                }
            }
            else
            {
                if (string.IsNullOrEmpty(SelectedModule) == true && Entity.FolderOnly == false)
                {
                    MSD.AddModelError("SelectedModule", "请选择一个模块");
                    return;
                }

                if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
                {
                    var modules = GlobalServices.GetRequiredService <GlobalData>().AllModule;
                    var ndc     = DC.ReCreate();
                    var oldIDs  = ndc.Set <FrameworkMenu>().Where(x => x.ParentId == Entity.ID).Select(x => x.ID).ToList();
                    foreach (var oldid in oldIDs)
                    {
                        try
                        {
                            FrameworkMenu fp = new FrameworkMenu {
                                ID = oldid
                            };
                            ndc.Set <FrameworkMenu>().Attach(fp);
                            ndc.DeleteEntity(fp);
                        }
                        catch { }
                    }
                    ndc.SaveChanges();
                    var mo = modules.Where(x => x.ClassName == this.SelectedModule && x.IsApi == true).FirstOrDefault();
                    Entity.ModuleName = mo.ModuleName;
                    Entity.ClassName  = mo.ClassName;
                    Entity.MethodName = null;

                    var otherActions = mo.Actions;
                    int order        = 1;
                    foreach (var action in otherActions)
                    {
                        if (SelectedActionIDs != null && SelectedActionIDs.Contains(action.MethodName))
                        {
                            FrameworkMenu menu = new FrameworkMenu();
                            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;
                            menu.PageName     = action.ActionName;
                            menu.ModuleName   = action.Module.ModuleName;
                            menu.ActionName   = action.ActionName;
                            menu.Url          = action.Url;
                            menu.ClassName    = action.Module.ClassName;
                            menu.MethodName   = action.MethodName;
                            Entity.Children.Add(menu);
                        }
                    }
                }

                else
                {
                    Entity.Children = null;
                    Entity.Url      = null;
                }
            }
            base.DoEdit(updateAllFields);
            List <Guid> guids = new List <Guid>();

            guids.Add(Entity.ID);
            if (Entity.Children != null)
            {
                guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
            }
            AddPrivilege(guids);
        }
Пример #8
0
        public override void DoAdd()
        {
            if (Entity.IsInside == false)
            {
                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;
                        }
                    }
                }
            }
            else
            {
                if (string.IsNullOrEmpty(SelectedModule) == false && Entity.FolderOnly == false)
                {
                    var modules = GlobalServices.GetRequiredService <GlobalData>().AllModule;
                    List <FrameworkAction> otherActions = null;
                    var mainAction = modules.Where(x => x.FullName == this.SelectedModule).SelectMany(x => x.Actions).Where(x => x.MethodName == "Index").SingleOrDefault();
                    if (mainAction == null)
                    {
                        MSD.AddModelError("Entity.ModuleId", "模块中没有找到Index页面");
                        return;
                    }
                    var ndc    = DC.ReCreate();
                    var oldIDs = ndc.Set <FrameworkMenu>().Where(x => x.ParentId == Entity.ID).Select(x => x.ID).ToList();
                    foreach (var oldid in oldIDs)
                    {
                        try
                        {
                            FrameworkMenu fp = new FrameworkMenu {
                                ID = oldid
                            };
                            ndc.Set <FrameworkMenu>().Attach(fp);
                            ndc.DeleteEntity(fp);
                        }
                        catch { }
                    }
                    ndc.SaveChanges();

                    Entity.Url = "/" + mainAction.Module.ClassName + "/" + mainAction.MethodName;
                    if (mainAction.Module.Area != null)
                    {
                        Entity.Url = "/" + mainAction.Module.Area.Prefix + Entity.Url;
                    }
                    Entity.ModuleName = mainAction.Module.ModuleName;

                    otherActions = modules.Where(x => x.FullName == this.SelectedModule).SelectMany(x => x.Actions).Where(x => x.MethodName != "Index").ToList();
                    int order = 1;
                    foreach (var action in otherActions)
                    {
                        if (SelectedActionIDs.Contains(action.Url))
                        {
                            FrameworkMenu menu = new FrameworkMenu();
                            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;
                            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);
                        }
                    }
                }

                else
                {
                    Entity.Children = null;
                    Entity.Url      = null;
                }
            }
            base.DoAdd();
            List <Guid> guids = new List <Guid>();

            guids.Add(Entity.ID);
            if (Entity.Children != null)
            {
                guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
            }
            AddPrivilege(guids);
        }
Пример #9
0
        public override void DoAdd()
        {
            if (Entity.IsInside == false)
            {
                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;
                        }
                    }
                }
            }
            else
            {

                if (Entity.ModuleId != null && Entity.FolderOnly == false)
                {
                    List<FrameworkAction> otherActions = null;
                    var mainAction =  DC.Set<FrameworkAction>().Include(x => x.Module.Area).Where(x => x.ModuleId == this.Entity.ModuleId && x.MethodName == "Index").SingleOrDefault();
                    if (mainAction == null)
                    {
                        MSD.AddModelError("Entity.ModuleId", "模块中没有找到Index页面");
                        return;
                    }
                    Entity.ActionId = mainAction.ID;
                    Entity.Url = "/" + mainAction.Module.ClassName + "/" + mainAction.MethodName;
                    if (mainAction.Module.Area != null)
                    {
                        Entity.Url = "/" + mainAction.Module.Area.Prefix + Entity.Url;
                    }

                    otherActions = DC.Set<FrameworkAction>().Include(x => x.Module.Area).Where(x => x.ModuleId == this.Entity.ModuleId && x.ID != Entity.ActionId).ToList();
                    int order = 1;
                    foreach (var action in otherActions)
                    {
                        if (SelectedActionIDs.Contains(action.ID))
                        {
                            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;
                            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);
                        }
                    }
                }

                else
                {
                    Entity.Children = null;
                    Entity.ModuleId = null;
                    Entity.Url = null;
                }

            }
            base.DoAdd();
            List<Guid> guids = new List<Guid>();
            guids.Add(Entity.ID);
            if (Entity.Children != null)
            {
                guids.AddRange(Entity.Children?.Select(x => x.ID).ToList());
            }
            AddPrivilege(guids);
        }