public List <Category> getAllListCategory() { TSQLContext dbContext = new TSQLContext(); return(dbContext.Category.ToList()); // SqlConnection connection= new SqlConnection(); //connection.ConnectionString="Server=DESKTOP-LDF80HU;Database=TSQL2012;Trusted_Connection=True"; //connection.Open(); //SqlCommand command= new SqlCommand(); //command.CommandType=CommandType.Text; //command.CommandText=$@"select*from Production.Categories "; //command.Connection=connection; //SqlDataReader reader = command.ExecuteReader(); // List<Category> item=new List<Category>(); //while(reader.Read()) // { // Category temp1=new Category(); // temp1.categoryName=reader["categoryname"].ToString(); // temp1.categoryID=int.Parse(reader["categoryid"].ToString()); // item.Add(temp1); // item.Add(new SelectListItem { Text = temp1.campanyName,Value=temp1.supplierID.ToString()}); // } // return item; }
/* SqlConnection connection= new SqlConnection(); * connection.ConnectionString="Server=DESKTOP-LDF80HU;Database=TSQL2012;Trusted_Connection=True"; * connection.Open(); * SqlCommand command= new SqlCommand(); * * command.CommandText=$@"Select * from GetAllProducts where productname like '%{searchP}%' order by {sortBy} OFFSET {page*5} ROWS FETCH NEXT 5 ROWS ONLY "; * command.Connection=connection; * * SqlDataReader reader = command.ExecuteReader(); * * List <Product> productNames=new List<Product>(); * while(reader.Read()) * { * Product temp= new Product(); * temp.ProductID=int.Parse(reader["productid"].ToString()); * temp.ProductName=reader["productname"].ToString(); * temp.SupplierID=int.Parse(reader["supplierid"].ToString()); * temp.CategoryID=int.Parse(reader["categoryid"].ToString()); * temp.UnitPrice=decimal.Parse(reader["unitprice"].ToString()); * temp.Discontinued=bool.Parse(reader["discontinued"].ToString()); * productNames.Add(temp); * } * return productNames; * * } * SqlConnection connection= new SqlConnection(); * connection.ConnectionString="Server=DESKTOP-LDF80HU;Database=TSQL2012;Trusted_Connection=True"; * connection.Open(); * SqlCommand command= new SqlCommand(); * * command.CommandText=$@"Select * from GetAllProducts where productname like '%{searchP}%' order by {sortBy} OFFSET {page*5} ROWS FETCH NEXT 5 ROWS ONLY "; * command.Connection=connection; * * SqlDataReader reader = command.ExecuteReader(); * * List <Product> productNames=new List<Product>(); * while(reader.Read()) * { * Product temp= new Product(); * temp.ProductID=int.Parse(reader["productid"].ToString()); * temp.ProductName=reader["productname"].ToString(); * temp.SupplierID=int.Parse(reader["supplierid"].ToString()); * temp.CategoryID=int.Parse(reader["categoryid"].ToString()); * temp.UnitPrice=decimal.Parse(reader["unitprice"].ToString()); * temp.Discontinued=bool.Parse(reader["discontinued"].ToString()); * productNames.Add(temp); * } * return productNames; * * }/* */ public void AddProduct(Product p) { TSQLContext dbContext = new TSQLContext(); dbContext.Products.Add(p); dbContext.SaveChanges(); //po wyslaniu na serwer przełacza na liste produktów // SqlConnection connection= new SqlConnection(); // connection.ConnectionString="Server=DESKTOP-LDF80HU;Database=TSQL2012;Trusted_Connection=True"; // connection.Open(); // SqlCommand command= new SqlCommand(); // command.CommandType=CommandType.Text; // command.CommandText=$"exec [dbo].[addProduct] {p.ProductName},{p.SupplierID},{p.CategoryID},{p.UnitPrice} ,{p.Discontinued}"; // command.Connection=connection; // command.ExecuteNonQuery(); }
public List <Suppliers> GetAllSuppliers(string searchS, string sortBy) { TSQLContext dbContext = new TSQLContext(); return(dbContext.Suppliers.ToList()); //SqlConnection connection=new SqlConnection(); //connection.ConnectionString="Server=DESKTOP-LDF80HU;Database=TSQL2012;Trusted_Connection=True"; //connection.Open(); // SqlCommand command=new SqlCommand(); // command.CommandText=$@"select * from Production.Suppliers where companyname like '%{searchS}%' OR contactname like '%{searchS}%' order by {sortBy} " ; // command.Connection=connection; // SqlDataReader reader=command.ExecuteReader(); // List <Suppliers> suppliersName=new List<Suppliers>(); // while(reader.Read()) // { // Suppliers temp=new Suppliers(); // temp.supplierID=int.Parse(reader["supplierid"].ToString()); // temp.campanyName= reader["companyname"].ToString(); // temp.contacName= reader["contactname"].ToString(); // temp.contactittle= reader["contacttitle"].ToString(); // temp.adress= reader["address"].ToString(); // temp.city= reader["city"].ToString(); // temp.region= reader["region"].ToString(); // temp.postalCode= reader["postalcode"].ToString(); // temp.country= reader["country"].ToString(); // temp.phone= reader["phone"].ToString(); // temp.fax= reader["fax"].ToString(); // suppliersName.Add(temp); // } // return suppliersName; }
public List <Product> GetAllProducts(string sortBy, string searchP, int page) { TSQLContext dbContext = new TSQLContext(); return(dbContext.Products.ToList()); }