public IQueryable <UserPreference> Select(string expand = null) { using (log.Activity(m => m($"Selecting {nameof(UserPreference)} with [{expand}] by {Thread.CurrentPrincipal?.Identity?.Name}"))) { var entities = null as IQueryable <UserPreference>; using (log.Activity(m => m("Create Query"))) { entities = context.UserPreferences .AsNoTracking() .Expand(expand); } using (log.Activity(m => m("Authorization"))) { try { entities = security.ValidateSelect(entities, expand); } catch (UnauthorizedAccessException) { log.Warn($"Authorization Denied"); throw; } catch (Exception e) { log.Error($"Authorization Error", e); throw; } } var values = null as IQueryable <UserPreference>; using (log.Activity(m => m("Filtering"))) { try { values = entities.Filters(expand).AsQueryable(); } catch (Exception e) { log.Error($"Filtering Error", e); throw; } } log.Info(m => m($"Selected {nameof(UserPreference)}[{string.Join(",", values.Select(item => item.Id))}] with [{expand}] by {Thread.CurrentPrincipal?.Identity?.Name}")); return(values); } }
public IQueryable <AttentionNoticeStatus> Select(string expand = null, string filter = null) { using (log.Activity(m => m($"Selecting {nameof(AttentionNoticeStatus)} with expand[{expand}] and filter[{filter}] by {Thread.CurrentPrincipal?.Identity?.Name}"))) { var entities = null as IQueryable <AttentionNoticeStatus>; using (log.Activity(m => m("Create Query"))) { entities = context.AttentionNoticeStatuses .AsNoTracking() .Expand(expand); //TODO: KB: It must be one dynamic linq or odata or typed filter if (!string.IsNullOrWhiteSpace(filter)) { var keys = filter.Split(',').ToList(); entities = entities .Where(item => keys.Contains(item.Key)); } } using (log.Activity(m => m("Authorization"))) { try { entities = security.ValidateSelect(entities, expand); } catch (UnauthorizedAccessException) { log.Warn($"Authorization Denied"); throw; } catch (Exception e) { log.Error($"Authorization Error", e); throw; } } var values = null as IQueryable <AttentionNoticeStatus>; using (log.Activity(m => m("Filtering"))) { try { values = entities.Filters(expand).AsQueryable(); } catch (Exception e) { log.Error($"Filtering Error", e); throw; } } using (log.Activity(m => m("Emit Event"))) { try { accessEmitter.OnSelected(values.ToList()); } catch (Exception e) { log.Error($"Emit Event Error", e); throw; } } log.Info(m => m($"Selected {nameof(AttentionNoticeStatus)}[{string.Join(",", values.Select(item => item.Id))}] with [{expand}] by {Thread.CurrentPrincipal?.Identity?.Name}")); return(values); } }