Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string GetSoldProducts(ProductShopContext context)
- {
- var users = context.Users
- .Where(u => u.ProductsSold.Count > 0 && u.ProductsSold.Any(a => a.BuyerId != null))
- .Select(a => new
- {
- FirstName = a.FirstName,
- LastName = a.LastName,
- SoldProducts = a.ProductsSold
- .Select(b => new
- {
- b.Name,
- Price = b.Price.ToString("F2"),
- BuyerFirstName = b.Buyer.FirstName,
- BuyerLastName = b.Buyer.LastName
- })
- }).OrderBy(x => x.LastName).ThenBy(x => x.FirstName).ToList();
- var resolver = new DefaultContractResolver()
- {
- NamingStrategy = new CamelCaseNamingStrategy()
- };
- var sett = new JsonSerializerSettings();
- sett.ContractResolver = resolver;
- sett.Formatting = Formatting.Indented;
- var json = JsonConvert.SerializeObject(users, sett);
- return json;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement