public static AppUsefulLinks ToAppUsefulLinks(this UsefulLinks link, UsefulLinksTypeEnum type) { if (type == UsefulLinksTypeEnum.ParentOnly) { return(new AppUsefulLinks() { Id = link.Id, LinkName = link.LinkName, ChildLinks = link.Childs.Select(_ => new AppUsefulLinks() { LinkName = _.LinkName, ParentId = _.ParentId, URL = _.URL, Id = _.Id, ParentLink = new AppUsefulLinks() { Id = _.ParentId.GetValueOrDefault(), LinkName = _.LinkName, URL = _.URL } }), URL = link.URL }); } else if (type == UsefulLinksTypeEnum.ChildOnly) { return(new AppUsefulLinks() { Id = link.Id, LinkName = link.LinkName, ParentId = link.ParentId, ParentLink = new AppUsefulLinks() { Id = link.ParentId, URL = link.ParentUsefulLink.URL, LinkName = link.ParentUsefulLink.LinkName, ChildLinks = link.Childs.Select(_ => new AppUsefulLinks() { Id = _.Id, LinkName = _.LinkName, URL = _.URL }) }, URL = link.URL }); } else { return(new AppUsefulLinks() { Id = link.Id, LinkName = link.LinkName, ChildLinks = link.Childs == null? null: link.Childs.Select(_ => new AppUsefulLinks() { LinkName = _.LinkName, ParentId = _.ParentId, URL = _.URL, Id = _.Id, ParentLink = new AppUsefulLinks() { Id = _.ParentId.GetValueOrDefault(), LinkName = _.LinkName, URL = _.URL } }), URL = link.URL }); } }
// Get all categories public IEnumerable <AppUsefulLinks> GetAllUsefulLinks(UsefulLinksTypeEnum type) { IEnumerable <AppUsefulLinks> results = null; switch (type) { case UsefulLinksTypeEnum.ParentOnly: results = _linksRepose.GetAllUsefulLinks().Where(_ => _.ParentUsefulLink == null).Select(_ => _.ToAppUsefulLinks(type)); break; case UsefulLinksTypeEnum.ChildOnly: results = _linksRepose.GetAllUsefulLinks().Where(_ => _.ParentUsefulLink != null).Select(_ => _.ToAppUsefulLinks(type)); break; case UsefulLinksTypeEnum.All: results = _linksRepose.GetAllUsefulLinks().Select(_ => _.ToAppUsefulLinks(type)); break; } return(results); }