public async Task <JsonListUser> Get([FromBody] JsonListSettings settings) { try { // Initialisation... if (settings == null) { settings = new JsonListSettings() { Count = 0, Skip = 0, Take = 20, Filters = new Dictionary <string, string>() { } }; if (settings == null) { _Log.LogCritical("Not enough memory to allocate a new JsonListSettings!"); return(null); } } // Get users based on filter... UserProvider provider = new UserProvider(AppContext); Dictionary <string, object> filters = provider?.ConvertFilter(settings.Filters); IEnumerable <ApplicationUser> users = await provider?.Get(filters, settings.Skip, settings.Take); JsonListUser list = new JsonListUser(settings, users?.Select(p => new JsonUser(AppContext, p))); if (settings.Skip == 0 && settings.Count == 0 && list != null) { // Get users total count... list.Settings.Count = await provider?.Count(filters); } return(list); } catch { return(null); } }
/// <summary> /// Constructor. /// </summary> /// <param name="settings"></param> /// <param name="users"></param> public JsonListUser(JsonListSettings settings, IEnumerable <JsonUser> users) { _users = users; _settings = settings; }
/// <summary> /// Constructor. /// </summary> /// <param name="settings"></param> /// <param name="posts"></param> public JsonListPost(JsonListSettings settings, IEnumerable <JsonPost> posts) { _posts = posts; _settings = settings; }
public async Task <JsonListPost> Get([FromBody] JsonListSettings settings) { try { // Initialisation... Dictionary <string, string> defaultFilters = settings?.DefaultFilters; if (settings == null || settings.Filters == null) { settings = new JsonListSettings() { Count = 0, Skip = 0, Take = 20, Filters = new Dictionary <string, string>() { { QueryFilter.MineToo, "true" } } }; if ((AppContext.User?.HasRole(ClaimValueRole.Administrator) ?? false) == true || (AppContext.User?.HasRole(ClaimValueRole.Publicator) ?? false) == true) { settings.Filters.Add(QueryFilter.State, "-1"); } else { settings.Filters.Add(QueryFilter.State, "1"); } if (settings == null || settings.Filters == null) { _Log.LogCritical("Not enough memory to allocate a new JsonListSettings!"); return(null); } } if (defaultFilters != null) { foreach (KeyValuePair <string, string> kp in defaultFilters) { settings.Filters.Add(kp.Key, kp.Value); } } // By default: Always add childs items of the categories... if (settings.Filters.ContainsKey(QueryFilter.ShowChildsCategoriesPosts) == false) { settings.Filters.Add(QueryFilter.ShowChildsCategoriesPosts, "true"); } // Get posts based on filter... PostProvider provider = new PostProvider(AppContext); Dictionary <string, object> filters = provider?.ConvertFilter(settings.Filters); IEnumerable <Post> posts = await provider?.Get(filters, settings.Skip, settings.Take); JsonListPost list = new JsonListPost(settings, posts?.Select(p => new JsonPost(AppContext, p))); if (settings.Skip == 0 && settings.Count == 0 && list != null) { // Get posts total count... list.Settings.Count = await provider?.Count(filters); } // Clean settings... if (defaultFilters != null) { foreach (KeyValuePair <string, string> kp in defaultFilters) { settings.Filters.Remove(kp.Key); } } return(list); } catch (Exception e) { AppContext?.Log?.LogError("Exception getting posts - HttpPost:/api/post/list: {0}", e.Message); return(null); } }