Esempio n. 1
0
        public async Task <IEnumerable <SelectListItem> > GetTreeSubdivisions(string hashIdSelectedValue = null)
        {
            var treeSubdivisions = await _subdivisionsService.GetTreeSubdivisions();

            var subdivision = treeSubdivisions.ToList();
            var group       = subdivision.Select(m => new SelectListGroup {
                Name = m.GroupName
            }).ToList();
            var items = new List <SelectListItem>();
            var j     = 0;

            for (var i = 0; i < subdivision.Count; i++)
            {
                for (; j < group.Count;)
                {
                    items.AddRange(subdivision.ElementAt(i).Subdivisions.Select(subdivisionDto => new SelectListItem
                    {
                        Value    = subdivisionDto.HashIdMain,
                        Text     = subdivisionDto.Name,
                        Group    = group[j],
                        Selected = subdivisionDto.HashIdMain == hashIdSelectedValue
                    }));
                    break;
                }
                j++;
            }
            return(items);
        }