Example #1
0
        public static CourseInfo getCourseInfo(int courseID)
        {
            CourseInfo courseInfo = null;

            try
            {
                DataAccessLayer DAL = new DataAccessLayer();
                DataTable dt = DAL.select(String.Format("CourseID = '{0}'", courseID), "CourseInfo");

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

                    string courseName = Convert.ToString(row["CourseName"]);
                    string description = Convert.ToString(row["Description"]);

                    courseInfo = new CourseInfo(courseName, description);
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving the course information --- " + ex.Message);
            }

            return courseInfo;
        }
Example #2
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);
            }
        }
Example #3
0
        public static int insert(CourseInfo newCourseInfo)
        {
            int id = -1;

            try
            {
                DataAccessLayer DAL = new DataAccessLayer();
                DataTable dt = DAL.select(String.Format("CourseName = '{0}'", newCourseInfo.CourseName), "CourseInfo");

                if (dt == null || dt.Rows.Count == 0)
                {
                    Dictionary<string, string> courseInfo = new Dictionary<string, string>();
                    courseInfo.Add("CourseName", newCourseInfo.CourseName);
                    courseInfo.Add("Description", newCourseInfo.Description);
                    courseInfo.Add("IsActive", "1");
                    courseInfo.Add("IsDeleted", "0");
                    courseInfo.Add("CreatedDate", Convert.ToString(DateTime.Now));
                    courseInfo.Add("ModifiedDate", Convert.ToString(DateTime.Now));
                    id = DAL.insert(courseInfo, "CourseInfo");
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in adding a new course --- " + ex.Message);
            }

            return id;
        }