示例#1
0
 public static void SetInstance(string ConnectionString)
 {
     if (Instance == null)
     {
         Instance = new TraderRepo(ConnectionString);
     }
 }
示例#2
0
        private IEnumerable <ItemModel> ItemCondition(string condition)

        {
            if (!String.IsNullOrEmpty(condition) && !condition.Equals("*"))
            {
                condition = " where " + condition;
            }
            else
            {
                condition = "";
            }
            Console.WriteLine("Select * from dbo.Items" + condition);
            List <ItemModel> MyList = new List <ItemModel>();
            ItemModel        curr;

            sqlConnection.Open();
            var arg = "Select * from dbo.Items" + condition;

            using (var command = new SqlCommand(arg, sqlConnection))
            {
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        curr             = new ItemModel();
                        curr.ID          = reader["ID"] as string;
                        curr.Name        = reader["Name"] as string;
                        curr.Description = reader["Description"] as string;
                        string owner = reader["OwnerId"] as string;
                        curr.OwnerId = TraderRepo.GetInstance().GetById(owner);
                        string price = reader["Price"] + "";
                        curr.Price = Int32.Parse(price);
                        curr.Photo = reader["Photo"] as byte[];
                        curr.Tags  = TagAssocRepo.GetInstance().ItemTags(curr.ID);
                        MyList.Add(curr);
                    }
                }
            }
            sqlConnection.Close();
            return(MyList);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }