private List <ItemModel> ItemsWithTag(string condition) { if (!String.IsNullOrEmpty(condition) && !condition.Equals("*")) { condition = " where Tag_ID = \'" + condition + "\'"; } else { condition = ""; } Console.WriteLine("Select * from dbo.TagAssoc" + condition); List <ItemModel> MyList = new List <ItemModel>(); ItemModel curr; sqlConnection.Open(); var arg = "Select * from dbo.TagAssoc" + condition; using (var command = new SqlCommand(arg, sqlConnection)) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { string itemid = reader["Tag_ID"] as string; curr = ItemRepo.GetInstance().GetItem(itemid); MyList.Add(curr); } } } sqlConnection.Close(); return(MyList); }
private IEnumerable <ReviewModel> ReviewCondition(string condition) { if (!String.IsNullOrEmpty(condition) && !condition.Equals("*")) { condition = " where " + condition; } else { condition = ""; } Console.WriteLine("Select * from dbo.Reviews" + condition); List <ReviewModel> MyList = new List <ReviewModel>(); ReviewModel curr; sqlConnection.Open(); var arg = "Select * from dbo.Reviews" + condition; using (var command = new SqlCommand(arg, sqlConnection)) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { curr = new ReviewModel(); curr.ID = reader["Trans_ID"] as string; string a = reader["Author"] as string; string i = reader["Item_ID"] as string; curr.Author = TraderRepo.GetInstance().GetById(a); curr.Item = ItemRepo.GetInstance().GetItem(i); curr.Review = reader["Review"] as string; a = reader["stars"] + ""; curr.Stars = Double.Parse(a); MyList.Add(curr); } } } sqlConnection.Close(); return(MyList); }
private IEnumerable <TransactionModel> TransactionCondition(string condition) { if (!String.IsNullOrEmpty(condition) && !condition.Equals("*")) { condition = " where " + condition; } else { condition = ""; } Console.WriteLine("Select * from dbo.Transactions" + condition); List <TransactionModel> MyList = new List <TransactionModel>(); TransactionModel curr; sqlConnection.Open(); var arg = "Select * from dbo.Transactions" + condition; using (var command = new SqlCommand(arg, sqlConnection)) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { curr = new TransactionModel(); curr.ID = reader["Trans_ID"] as string; string b = reader["Buyer_ID"] as string; string s = reader["Seller_ID"] as string; string i = reader["Item_ID"] as string; curr.Buyer = TraderRepo.GetInstance().GetById(b); curr.Seller = TraderRepo.GetInstance().GetById(s); curr.Item = ItemRepo.GetInstance().GetItem(i); MyList.Add(curr); } } } sqlConnection.Close(); return(MyList); }