protected override Dictionary <string, IEnumerable <DtoBase> > FlattenRelatedEntities(List <M.Role> models, string expand) { // TODO: Move it to a place where it can be universally applied // Here we artificially include Permissions/Views since it is not a navigation // property in the DB and therefore will throw an error in the default implementation string nonDbExpand = "Permissions/View"; if (expand != null && expand.Contains(nonDbExpand)) { // Take out the non DB Expand term and call the default implementation on the rest var dbExpands = expand.Split(',').Select(e => e.Trim()).Where(e => e != nonDbExpand).ToList(); dbExpands.Add("Permissions"); Dictionary <string, IEnumerable <DtoBase> > result = base.FlattenRelatedEntities(models, string.Join(",", dbExpands)); // Manually include the views by invoking the Views repository var viewIds = models.SelectMany(e => e.Permissions).Select(e => e.ViewId).Where(e => e != null).Distinct(); var repo = new ViewsRepository(_db, _localizer, _tenantInfoAccessor); var allViews = repo.GetAllViews().ToDictionary(e => e.Id); var viewList = new List <View>(viewIds.Count()); foreach (var viewId in viewIds) { if (allViews.ContainsKey(viewId)) { var viewDef = allViews[viewId]; viewList.Add(_mapper.Map <View>(viewDef)); } } result["Views"] = viewList; return(result); } else { return(base.FlattenRelatedEntities(models, expand)); } }
protected override IQueryable <ViewDefinition> GetBaseQuery() { var repo = new ViewsRepository(_db, _localizer, _accessor); return(repo.GetAllViews().AsQueryable()); }