public static string GetUsersWithProducts(ProductShopContext context) { var allUsers = context.Users .Where(x => x.ProductsSold.Any(p => p.Buyer != null)) .OrderByDescending(x => x.ProductsSold.Count(ps => ps.Buyer != null)) .Select(x => new UserView { FirstName = x.FirstName, LastName = x.LastName, Age = x.Age, SoldProducts = new AllSoldProductsView { Count = x.ProductsSold.Where(ps => ps.Buyer != null).Count(), Products = x.ProductsSold.Where(ps => ps.Buyer != null) .Select(ps => new ProductView { Name = ps.Name, Price = ps.Price }).ToList() } }).ToList(); var data = new AllUsersView { UsersCount = allUsers.Count, Users = allUsers }; var json = JsonConvert.SerializeObject(data, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented }); return(json); }
public async Task NavigateForward(AbstractViewModel vm) { ContentPage cp = null; bool isPopup = vm is IPopupViewModel; if (vm is LoginViewModel) { cp = new LoginView(); } else if (vm is AllSnippetsViewModel) { cp = new AllSnippetsView(); } else if (vm is AllUsersViewModel) { cp = new AllUsersView(); } else if (vm is YesNoPageViewModel) { cp = new YesNoPageView(); } else if (vm is SnippetViewModel) { cp = new SnippetView(); } else if (vm is UserViewModel) { cp = new UserView(); } else if (vm is VariableViewModel) { cp = new VariableView(); } else if (vm is MenuViewModel) { cp = new MenuView(); } else if (vm is AlertViewModel) { cp = new AlertView(); } else if (vm is ProfileViewModel) { cp = new ProfileView(); } else if (vm is TextInputViewModel) { cp = new TextInputView(); } cp.BindingContext = vm; await Task.Delay(100); if (isPopup) { SetHasBackButton(cp, false); await Navigation.PushModalAsync(cp); } else { await Navigation.PushAsync(cp); } }