async Task LoadCustomAttributes(CustomAttributeListQueryModel queryModel = null) { loading = true; try { attributes = await Client.GetCustomAttributes(queryModel); } finally { StateHasChanged(); loading = false; } }
public CustomAttributeListModel GetCustomAttributes(CustomAttributeListQueryModel queryModel) { if (queryModel is null) { queryModel = new CustomAttributeListQueryModel(); } var customAttributesQuery = Database.CustomAttributes; if (queryModel.ActiveOnly) { customAttributesQuery = customAttributesQuery.Active(); } if (!string.IsNullOrWhiteSpace(queryModel.Query)) { customAttributesQuery = customAttributesQuery.Where(c => c.Name.Contains(queryModel.Query)); } int skip = (queryModel.Page - 1) * queryModel.Size; int total = customAttributesQuery.Count(); var items = customAttributesQuery .OrderBy(c => c.Name) .Select(c => new CustomAttributeListModel.ListItem { Id = c.Id, Name = c.Name, DataType = c.DataType, Deleted = c.Deleted, UnitOfMeasure = c.UnitOfMeasure }).ToArray(); double pages = total / queryModel.Page; var model = new CustomAttributeListModel { Total = total, CurrentPage = pages == 0 ? 0 : queryModel.Page, TotalPages = Convert.ToInt32(Math.Ceiling(pages)), Items = items }; return(model); }