Beispiel #1
0
        public static int createTextBook(Textbook book)
        {
            int BookId = -1;

            try
            {
                DataAccess da = new DataAccess();
                DataTable dt = da.select(String.Format("ISBN = '{0}'", book.ISBN), "TextBooks", NumRows : 1);

                if (dt == null || dt.Rows.Count == 0)
                {
                    Dictionary<string, object> textbook = new Dictionary<string, object>();
                    textbook.Add("ISBN", book.ISBN);
                    textbook.Add("BookTitle", book.BookTitle);
                    textbook.Add("Author", book.Author);
                    textbook.Add("CourseId", book.CourseId);
                    textbook.Add("BookImageURL", book.BookImageUrl);
                    textbook.Add("StorePrice", book.StorePrice);
                    textbook.Add("IsActive", 1);
                    textbook.Add("IsDeleted", 0);
                    textbook.Add("CreatedDate", DateTime.Now);
                    textbook.Add("ModifiedDate", DateTime.Now);

                    BookId = da.insert(textbook, "TextBooks");
                }
            }
            catch (Exception ex) { Console.Write(ex.Message + "    " + ex.StackTrace); }

            return BookId;
        }
        public TransactionDetailModel(Transaction transaction)
        {
            Textbook textbook = TextbookHandler.getTextbook(transaction.TextbookId);

            SellerPost = PostHandler.getPost(transaction.SellerPostId);
            BuyerPost  = PostHandler.getPost(transaction.BuyerPostId);

            this.BookTitle   = textbook.BookTitle;
            this.ISBN        = textbook.ISBN;
            this.Price       = SellerPost.Price;
            this.FinalPrice  = transaction.FinalPrice;
            this.Condition   = SellerPost.BookCondition;
            this.CourseName  = CourseHandler.getCourseName(textbook.CourseId);
            this.StorePrice  = textbook.StorePrice;
            this.transaction = transaction;
        }
Beispiel #3
0
        public static IEnumerable<Textbook> getAllTextbooks()
        {
            List<Textbook> textbooks = new List<Textbook>();

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

                if (dt != null)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        int textbookId = Convert.ToInt32(row["TextBookId"]);
                        string bookTitle = Convert.ToString(row["BookTitle"]);
                        string isbn = Convert.ToString(row["ISBN"]);
                        string author = Convert.ToString(row["Author"]);
                        string bookImageUrl = row["BookImageURL"] is DBNull ? null : Convert.ToString(row["BookImageURL"]);

                        int courseId = Convert.ToInt32(row["CourseId"]);
                        string courseName = CourseHandler.getCourseName(courseId);

                        decimal? storePrice = row["StorePrice"] is DBNull ? (decimal?) null : Convert.ToDecimal(row["StorePrice"]);
                        int isActive = Convert.ToInt32(row["IsActive"]);
                        int isDeleted = Convert.ToInt32(row["IsDeleted"]);
                        DateTime createdDate = Convert.ToDateTime(row["CreatedDate"]);
                        DateTime modifiedDate = Convert.ToDateTime(row["ModifiedDate"]);

                        Textbook textbook = new Textbook(
                            textbookId,
                            bookTitle,
                            isbn,
                            author,
                            courseId,
                            courseName,
                            bookImageUrl,
                            storePrice,
                            isActive,
                            isDeleted,
                            createdDate,
                            modifiedDate
                        );
                        textbooks.Add(textbook);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving all textbooks --- " + ex.Message);
            }

            return textbooks;
        }
Beispiel #4
0
        public static Textbook getTextbook(int textbookId)
        {
            Textbook book = null;

            try
            {
                DataAccess da = new DataAccess();
                DataTable dt = da.select(String.Format("TextBookId = '{0}' AND IsActive = 1 AND IsDeleted = 0", textbookId), "TextBooks", NumRows : 1);

                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];
                    string bookTitle = Convert.ToString(row["BookTitle"]);
                    string isbn = Convert.ToString(row["ISBN"]);
                    string author = Convert.ToString(row["Author"]);
                    string bookImageUrl = row["BookImageURL"] is DBNull ? null : Convert.ToString(row["BookImageURL"]);

                    int courseId = Convert.ToInt32(row["CourseId"]);
                    string courseName = CourseHandler.getCourseName(courseId);

                    decimal? storePrice = row["StorePrice"] is DBNull ? (decimal?)null : Convert.ToDecimal(row["StorePrice"]);
                    int isActive = Convert.ToInt32(row["IsActive"]);
                    int isDeleted = Convert.ToInt32(row["IsDeleted"]);
                    DateTime createdDate = Convert.ToDateTime(row["CreatedDate"]);
                    DateTime modifiedDate = Convert.ToDateTime(row["ModifiedDate"]);

                    book = new Textbook(
                        textbookId,
                        bookTitle,
                        isbn,
                        author,
                        courseId,
                        courseName,
                        bookImageUrl,
                        storePrice,
                        isActive,
                        isDeleted,
                        createdDate,
                        modifiedDate
                    );
                }

            }
            catch (Exception ex) { Console.Write(ex.Message + " " + ex.StackTrace); }

            return book;
        }
Beispiel #5
0
        public ActionResult CreatePost(CreatePostModel model)
        {
            if (ModelState.IsValid)
            {
                int textbookId = model.TextBookId;

                // if we have a new textbook, store it
                if (model.IsNewBook)
                {
                    // proceed if course id exists; otherwise create the course first
                    Course course = CourseHandler.getCourseByName(model.CourseName);
                    if (course == null)
                    {
                        model.CourseId = CourseHandler.CreateCourse(model.CourseName);
                    }

                    var newTextbook = new Textbook(
                        -1, // id doesnt matter here
                        model.BookTitle,
                        model.ISBN,
                        model.Author,
                        model.CourseId,
                        model.CourseName,
                        model.BookImageUrl,
                        null,
                        1,
                        0,
                        DateTime.Now,
                        DateTime.Now
                    );

                    textbookId = TextbookHandler.createTextBook(newTextbook);
                }

                int profileId = ProfileHandler.GetProfileId(User.Identity.Name);
                int price = model.Price;
                ActionBy actionBy = model.ActionBy;

                if (model.IsNegotiable)
                {
                    if (actionBy == ActionBy.Buyer)
                    {
                        price = int.MaxValue;
                    }
                    else
                    {
                        price = 0;
                    }
                }

                var newPost = new Post(
                    -1, // id doesnt matter here
                    profileId,
                    textbookId,
                    actionBy,
                    price,
                    model.BookCondition,
                    0,
                    1,
                    0,
                    DateTime.Now,
                    DateTime.Now
                );

                int postId = PostHandler.createPost(newPost);
                newPost.PostId = postId;
                Task.Run(() => QueueWorker.AddPost(newPost));

                // TODO: redirect to special "you've successfully created post" page
                // with links to create another buy/sell post
                return RedirectToAction("Index", "Home");
            }

            // If we got this far, something failed, redisplay form
            IEnumerable<Textbook> textBookCollection = TextbookHandler.getAllTextbooks();

            // test data
            //for(int i = 0; i < 100; i++) {
            //    Textbook book = new Textbook(
            //        i,
            //        "Financial Accounting " + i,
            //        "100000000000" + i,
            //        "Author " + i,
            //        100 + i,
            //        "AFM 10" + i,
            //        null,
            //        10 + i,
            //        1,
            //        0,
            //        DateTime.Now,
            //        DateTime.Now
            //    );
            //    textBookCollection.Add(book);
            //}

            model.PostTypes = SelectListUtility.getPostTypes();
            model.BookConditions = SelectListUtility.getBookConditions();
            model.Textbooks = textBookCollection;

            return View("CreatePost", model);
        }