Esempio n. 1
0
        public static IEnumerable<Textbook> getAllTextbooks()
        {
            List<Textbook> allTextbooks = new List<Textbook>();

            try
            {
                DataAccessLayer DAL = new DataAccessLayer();
                DataTable dt = DAL.select("", "TextBooks");

                foreach (DataRow row in dt.Rows)
                {
                    string isbn = Convert.ToString(row["ISBN"]);
                    string title = Convert.ToString(row["BookTitle"]);
                    string author = Convert.ToString(row["Author"]);
                    string bookImageURL = Convert.ToString(row["BookImageURL"]);

                    int courseID = Convert.ToInt32(row["CourseID"]);
                    string courseName = CourseInfoHandler.getCourseName(courseID);

                    int storePrice = Convert.ToInt32(row["StorePrice"]);

                    Textbook textbook = new Textbook(isbn, title, author, courseName, bookImageURL, storePrice);
                    allTextbooks.Add(textbook);
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving all textbooks --- " + ex.Message);
            }

            return allTextbooks;
        }
Esempio n. 2
0
        public static Textbook getTextbook(int textbookID)
        {
            Textbook textbook = null;

            try
            {
                DataAccessLayer DAL = new DataAccessLayer();
                DataTable dt = DAL.select(String.Format("TextBookID = '{0}'", textbookID), "TextBooks");

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

                    string isbn = Convert.ToString(row["ISBN"]);
                    string title = Convert.ToString(row["BookTitle"]);
                    string author = Convert.ToString(row["Author"]);
                    string bookImageURL = Convert.ToString(row["BookImageURL"]);

                    int courseID = Convert.ToInt32(row["CourseID"]);
                    string courseName = CourseInfoHandler.getCourseName(courseID);

                    int storePrice = Convert.ToInt32(row["StorePrice"]);

                    textbook = new Textbook(isbn, title, author, courseName, bookImageURL, storePrice);
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving the textbook --- " + ex.Message);
            }

            return textbook;
        }
Esempio n. 3
0
        public static int insert(Textbook newBook)
        {
            int id = -1;

            try
            {
                DataAccessLayer DAL = new DataAccessLayer();
                DataTable dt = DAL.select(String.Format("ISBN = '{0}'", newBook.ISBN), "TextBooks");

                if (dt == null || dt.Rows.Count == 0)
                {
                    int courseID = CourseInfoHandler.getCourseID(newBook.CourseName);

                    Dictionary<string, string> textbook = new Dictionary<string, string>();
                    textbook.Add("ISBN", newBook.ISBN);
                    textbook.Add("BookTitle", newBook.Title);
                    textbook.Add("Author", newBook.Author);
                    textbook.Add("CourseID", courseID.ToString());
                    textbook.Add("BookImageURL", newBook.BookImageURL);
                    textbook.Add("StorePrice", Convert.ToString(newBook.StorePrice));
                    textbook.Add("IsActive", "1");
                    textbook.Add("IsDeleted", "0");
                    textbook.Add("CreatedDate", Convert.ToString(DateTime.Now));
                    textbook.Add("ModifiedDate", Convert.ToString(DateTime.Now));
                    id = DAL.insert(textbook, "TextBooks");
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in adding a new textbook --- " + ex.Message);
            }

            return id;
        }
Esempio n. 4
0
        public static IEnumerable<Textbook> getTextbooksByCourse(string courseName)
        {
            List<Textbook> textbooks = new List<Textbook>();

            try
            {
                int[] courseIDs = CourseInfoHandler.getCourseIDs(courseName);

                foreach (int courseID in courseIDs)
                {
                    DataAccessLayer DAL = new DataAccessLayer();
                    DataTable dt = DAL.select(String.Format("CourseID = '{0}'", courseID), "TextBooks");

                    foreach (DataRow row in dt.Rows)
                    {
                        string isbn = Convert.ToString(row["ISBN"]);
                        string title = Convert.ToString(row["BookTitle"]);
                        string author = Convert.ToString(row["Author"]);
                        string bookImageURL = Convert.ToString(row["BookImageURL"]);

                        string full_courseName = CourseInfoHandler.getCourseName(courseID);

                        int storePrice = Convert.ToInt32(row["StorePrice"]);

                        Textbook textbook = new Textbook(isbn, title, author, full_courseName, bookImageURL, storePrice);
                        textbooks.Add(textbook);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving textbooks by course name --- " + ex.Message);
            }

            return textbooks;
        }
Esempio n. 5
0
        public ActionResult SaveBook(string isbn, 
                                     string title,
                                     string author,
                                     string course,
                                     string bookImageURL,
                                     bool isBuy,
                                     int price,
                                     string condition,
                                     string email,
                                     bool IsNegotiable)
        {
            int courseID = CourseInfoHandler.getCourseID(course);
            if (courseID == -1)
            {
                // TODO: Implement description for each course
                CourseInfo newCourse = new CourseInfo(course, String.Empty);
                CourseInfoHandler.insert(newCourse);
            }

            Textbook newBook = new Textbook(isbn, title, author, course, bookImageURL, price);
            int bookId = TextbookHandler.insert(newBook);

            string accesstoken = Convert.ToString(Session["AccessToken"]);
            UserProfile profile = AccountHandler.getUserProfile_Facebook(UserProfileUtil.getFacebookID(accesstoken));

            if (bookId >= 0)
            {
                return SavePost(profile.ProfileID, newBook.CourseName, newBook.Title, isBuy, price, condition, email, IsNegotiable);
            }
            else
            {
                return Json("Failed to insert textbook: " + newBook.Title);
            }
        }