public IActionResult Load(Int64 ID, Int64?groupID, Int64?langId)
        {
            GetGroupRelation operation = new GetGroupRelation();

            operation.ID      = ID;
            operation.GroupID = groupID;
            if (langId.HasValue)
            {
                operation.LangID = langId;
            }
            else
            {
                operation.LangID = 1;
            }

            var result = operation.QueryAsync().Result;

            if (result is ValidationsOutput)
            {
                return(Ok(new ApiResult <List <ValidationItem> >()
                {
                    Data = ((ValidationsOutput)result).Errors
                }));
            }
            else
            {
                return(Ok((List <GroupRelation>)result));
            }
        }
        public IActionResult LoadMenus(long?groupID, long?LanguageID)
        {
            GetGroupRelation operation = new GetGroupRelation();

            operation.GroupID = groupID;
            GetMenus getMenus = new GetMenus();

            getMenus.Type = 1;
            if (LanguageID.HasValue)
            {
                getMenus.LangID  = LanguageID;
                operation.LangID = LanguageID;
            }
            else
            {
                getMenus.LangID  = 1;
                operation.LangID = 1;
            }

            var System = (List <Menu>)getMenus.QueryAsync().Result;

            getMenus.Type = 2;
            var Modules = (List <Menu>)getMenus.QueryAsync().Result;

            getMenus.Type = 3;
            var SubModule = (List <Menu>)getMenus.QueryAsync().Result;

            getMenus.Type = 4;
            var Pages         = (List <Menu>)getMenus.QueryAsync().Result;
            var groups        = (List <GroupRelation>)operation.QueryAsync().Result;
            var relatedSystem = new List <System>();

            foreach (var ss in System)
            {
                var system = new System();
                system.ID         = ss.ID;
                system.Name       = ss.Name;
                system.children   = Modules.Where(x => x.SubMenuID == ss.ID).ToList();
                system.children   = system.children.Select(c => { c.Parent = ss; return(c); }).ToList();
                system.SubModuels = SubModule.Where(subModule => system.children.Where(x => x.ID == subModule.SubMenuID) != null).ToList();
                system.Pages      = Pages.Where(page => system.SubModuels.Where(x => x.ID == page.SubMenuID) != null).ToList();
                system.OrderChildrens();
                relatedSystem.Add(system);
            }

            var unRelatedSystem = GenrerateUnRelatedGroups(groups, relatedSystem);

            return(Ok(new { unRelatedMenu = unRelatedSystem, relatedMenu = relatedSystem }));
        }
        public IActionResult LoadActions(long?groupID, long?LanguageID)
        {
            GetGroupRelation operation = new GetGroupRelation();
            GetMenus         getMenus  = new GetMenus();

            getMenus.Type = 5;

            operation.GroupID = groupID;

            if (LanguageID.HasValue)
            {
                operation.LangID = LanguageID;
                getMenus.LangID  = LanguageID;
            }
            else
            {
                operation.LangID = 1;
                getMenus.LangID  = 1;
            }

            var         result  = operation.QueryAsync().Result;
            var         Actions = (List <Menu>)getMenus.QueryAsync().Result;
            var         groups  = (List <GroupRelation>)result;
            List <Menu> returnedRelatedActions   = new List <Menu>();
            List <Menu> returnedUnRelatedActions = new List <Menu>();

            if (groups.Count > 0)
            {
                foreach (var item in Actions)
                {
                    foreach (var group in groups)
                    {
                        if (group.RefrenceID == item.ID)
                        {
                            bool alreadyExist             = returnedRelatedActions.Contains(item);
                            bool alreadyExistInSecondList = returnedUnRelatedActions.Contains(item);
                            if (!alreadyExist && !alreadyExistInSecondList)
                            {
                                item.GroupRelationID = group.ID.Value;
                                returnedRelatedActions.Add(item);
                            }
                            else
                            {
                                item.GroupRelationID = group.ID.Value;
                                returnedRelatedActions.Add(item);
                                returnedUnRelatedActions.Remove(item);
                            }
                        }
                        else
                        {
                            bool alreadyExist            = returnedUnRelatedActions.Contains(item);
                            bool alreadyExistInFirstList = returnedRelatedActions.Contains(item);
                            if (!alreadyExist && !alreadyExistInFirstList)
                            {
                                item.GroupRelationID = group.ID.Value;
                                returnedUnRelatedActions.Add(item);
                            }
                        }
                    }
                }
            }
            else
            {
                returnedUnRelatedActions = Actions;
            }
            if (result is ValidationsOutput)
            {
                return(Ok(new ApiResult <List <ValidationItem> >()
                {
                    Data = ((ValidationsOutput)result).Errors
                }));
            }
            else
            {
                return(Ok(new { RelatedActions = returnedRelatedActions, UnRelatedActions = returnedUnRelatedActions }));
            }
        }