예제 #1
0
        public IActionResult GetSubjectTree(int?id)
        {
            if (id == null)
            {
                return(NotFound("Parrent category are not found!"));
            }


            SubjectTreeDto model = RecursionTree(id);

            if (model == null)
            {
                return(NotFound("Parrent category are not found!"));
            }

            JsonResult            TMP       = Json(model);
            JsonResult            tmp2      = TMP;
            List <SubjectTreeDto> modelList = new List <SubjectTreeDto> {
                model
            };

            return(Json(modelList));
        }
예제 #2
0
        private SubjectTreeDto RecursionTree(int?id)
        {
            TicketSubject rootE = _context.Set <TicketSubject>()?.Find(id);

            if (rootE == null)
            {
                return(null);
            }

            SubjectTreeDto root = new SubjectTreeDto
            {
                ParentId = rootE.ParentId, Text = rootE.TicketSubjectName
            };

            List <int> children =
                _context.Set <TicketSubject>()
                ?.GetAll()
                ?.Where(t => t.ParentId == id)
                ?.Select(s => s.TicketSubjectId)
                ?.ToList();

            if (children.Count() > 0)
            {
                for (int i = 0; i < children.Count(); i++)
                {
                    root.nodes.Add(RecursionTree(children.ElementAtOrDefault(i)));
                }
            }
            else
            {
                root.nodes = null;
            }



            return(root);
        }