Example #1
0
        public static IEnumerable<MarketPost> getAllMarketPosts(bool isBuyPost)
        {
            List<MarketPost> allMarketPosts = new List<MarketPost>();

            try
            {
                DataAccessLayer DAL = new DataAccessLayer();
                DataTable dt = DAL.select(String.Format("IsBuy = '{0}'", isBuyPost), "Posts");

                foreach (DataRow row in dt.Rows)
                {

                    int textBookID = Convert.ToInt32(row["TextBookID"]);
                    int profileID = Convert.ToInt32(row["ProfileID"]);
                    int price = Convert.ToInt32(row["Price"]);
                    int postID = Convert.ToInt32(row["PostID"]);
                    bool viaEmail = Convert.ToBoolean(row["viaEmail"]);
                    bool isNegotiable = Convert.ToBoolean(row["IsNegotiable"]);
                    bool isBuy = Convert.ToBoolean(row["IsBuy"]);
                    string condition = Convert.ToString(row["BookCondition"]);

                    DateTime datePosted = Convert.ToDateTime(row["CreatedDate"]);

                    UserProfile UserProfile = AccountHandler.getUserProfile(profileID);
                    string postedBy = UserProfile.Name;
                    string email = UserProfile.Email;

                    Textbook textbook = TextbookHandler.getTextbook(textBookID);
                    string title = textbook.Title;
                    string course = textbook.CourseName;
                    string isbn = textbook.ISBN;
                    string author = textbook.Author;
                    string bookImageURL = textbook.BookImageURL;
                    List<Bid> bids = BidHandler.getBids(postID);

                    MarketPost marketPost = new MarketPost(
                        title, isBuy, course,
                        condition, postedBy, datePosted,
                        isbn, author, bookImageURL,
                        price, bids, isNegotiable, email,
                        viaEmail, profileID, postID);

                    allMarketPosts.Add(marketPost);
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving all market posts --- " + ex.Message);
            }

            return allMarketPosts;
        }
Example #2
0
        public static MarketPost getMarketPost(int postID)
        {
            MarketPost marketPost = null;

            try
            {
                DataAccessLayer DAL = new DataAccessLayer();
                DataTable dt = DAL.select(String.Format("PostID = '{0}'", postID), "Posts");

                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];

                    int profileID = Convert.ToInt32(row["ProfileID"]);
                    UserProfile UserProfile = AccountHandler.getUserProfile(profileID);
                    string postedBy = UserProfile.Name;
                    string email = UserProfile.Email;

                    int textbookID = Convert.ToInt32(row["TextBookID"]);

                    Textbook textbook = TextbookHandler.getTextbook(textbookID);
                    string isbn = textbook.ISBN;
                    string title = textbook.Title;
                    string author = textbook.Author;
                    string course = textbook.CourseName;
                    string bookImageURL = textbook.BookImageURL;

                    bool isBuy = Convert.ToBoolean(row["IsBuy"]);
                    bool isNegotiable = Convert.ToBoolean(row["IsNegotiable"]);
                    string condition = Convert.ToString(row["BookCondition"]);
                    int price = Convert.ToInt32(row["Price"]);
                    DateTime datePosted = Convert.ToDateTime(row["CreatedDate"]);
                    List<Bid> bids = BidHandler.getBids(postID);
                    bool viaEmail = Convert.ToBoolean(row["viaEmail"]);

                    marketPost = new MarketPost(
                        title, isBuy, course,
                        condition, postedBy, datePosted,
                        isbn, author, bookImageURL,
                        price, bids, isNegotiable, email,
                        viaEmail, profileID, postID);
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving the market post --- " + ex.Message);
            }

            return marketPost;
        }