//Определить список товаров заданного поставщика public List <Product> GetProductsByProvider(string providerName) { ProductGateWay productGateWay = new ProductGateWay(connString); ProviderGateWay providerGateWay = new ProviderGateWay(connString); Provider ourNeeded = providerGateWay.GetAll().First(x => x.Name == providerName); return(productGateWay.GetAll().Where(x => x.ProviderId == ourNeeded.Id).ToList()); }
static void Main(string[] args) { string connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Product_ADO;" + "Integrated Security=true"; //var str = "MSSQLLocalDB; Initial Catalog = Product_ADO; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False"; //SqlConnection connection = new SqlConnection(str); ProviderGateWay gateWay = new ProviderGateWay(connectionString); // gateWay.Delete(1006); ; foreach (var item in gateWay.GetProviderByCat(new Category() { Name = "Mobile" })) { Console.WriteLine($"{item.Id} {item.Name} {item.City}"); } /* gateWay.Create(new ADO_Lib.Models.Product() * { Name = "Jacobs", * Price = 10 } * );*/ // var pr = gateWay.Get(5); //Console.WriteLine($"{pr.Id} {pr.Name} {pr.Price} "); //var cl = gateWay.GetProviderByCat(new ADO_Lib.Models.Category() //{ // Name = "Laptop" //}); //foreach (var item in cl) //{ // Console.WriteLine($"{item.Id} {item.Name} {item.City} "); //} //Product product = new Product() //{ // Id = 8, // Name = "Kontix -X", // Price = 7, // Category = new Category() { Id = 5 } //}; //gateWay.Update(product); Console.ReadLine(); }
//Определить всех поставщиков товаров заданной категории public List <Provider> GetProvidersByCategory(string categoryName) { ProviderGateWay providerGateWay = new ProviderGateWay(connString); List <Provider> providers = new List <Provider>(); List <int> l1 = GetProductsByCategory(categoryName).Select(x => x.ProviderId).ToList(); List <Provider> l2 = providerGateWay.GetAll().ToList(); List <Provider> res = new List <Provider>(); foreach (Provider item in l2) { if (l1.Any(c => c == item.Id)) { res.Add(item); } } return(res); }