コード例 #1
0
ファイル: TransactionComment.cs プロジェクト: hw3jung/Chanel
 public TransactionComment(int commentId, string comment, ActionBy actionBy, Transaction transaction)
 {
     CommentId = commentId;
     Comment = comment;
     TransactionId = transaction.TransactionId;
     Details = new TransactionDetailModel(transaction);
 }
コード例 #2
0
        public ActionResult ConfirmTransaction(Transaction transaction)
        {
            if (ModelState.IsValid)
            {
                TransactionHandler.ConfirmTransaction(transaction);
            }

            return RedirectToAction("Index", "Home");
        }
コード例 #3
0
        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;
        }
コード例 #4
0
ファイル: TransactionHandler.cs プロジェクト: hw3jung/Chanel
        public static bool CancelTransaction(Transaction transaction)
        {
            bool success = CreateForbiddenMatch(transaction.BuyerPostId, transaction.SellerPostId) > 0
                && CreateForbiddenMatch(transaction.SellerPostId, transaction.BuyerPostId) > 0;

            if (success)
            {
                Dictionary<string, object> updateDictionary = new Dictionary<string, object>();
                updateDictionary.Add("IsDeleted", 1);
                UpdateTransaction(transaction.TransactionId, updateDictionary);

                PostHandler.updatePostState(transaction.SellerPostId, 0);
                PostHandler.updatePostState(transaction.BuyerPostId, 0);

                Profile buyer = ProfileHandler.GetProfile(transaction.BuyerId);
                Profile seller = ProfileHandler.GetProfile(transaction.SellerId);

                Textbook book = TextbookHandler.getTextbook(transaction.TextbookId);
                EmailUtility.SendEmail(
                    Convert.ToString(buyer.Email),
                    Convert.ToString(buyer.Name),
                    "Your transaction has been cancelled",
                    String.Format("Item: {0}</br>{1} has cancelled the transaction with you!<br/>" +
                        "We'll try to match you with someone else for this item.",
                        book.BookTitle,
                        seller.Name)
                );

                EmailUtility.SendEmail(
                    Convert.ToString(seller.Email),
                    Convert.ToString(seller.Name),
                    "Your transaction has been cancelled",
                    String.Format("Item: {0}<br/>{1} has cancelled the transaction with you!<br/>" +
                        "We'll try to match you with someone else for this item.",
                        book.BookTitle,
                        buyer.Name)
                );

                Post sellerPost = PostHandler.getPost(transaction.SellerPostId);
                Post buyerPost = PostHandler.getPost(transaction.BuyerPostId);
                Task.Run(() => QueueWorker.AddPost(sellerPost));
                Task.Run(() => QueueWorker.AddPost(buyerPost));
            }

            return success;
        }
コード例 #5
0
        public TransactionCommentModel(Transaction transaction, string userName)
        {
            Details = new TransactionDetailModel(transaction);
            profile = ProfileHandler.GetProfile(userName);
            UserId = profile.ProfileId;
            UserDisplayName = profile.Name;
            UserFacebookId = profile.FacebookId;

            if (UserId == transaction.BuyerId)
            {
                CounterPartyId = transaction.SellerId;
                UserAction = ActionBy.Buyer;
            }
            else
            {
                CounterPartyId = transaction.BuyerId;
                UserAction = ActionBy.Seller;
            }

            Profile counterPartyProfile = ProfileHandler.GetProfile(CounterPartyId);
            CounterPartyDisplayName = counterPartyProfile.Name;
            CounterPartyFacebookId = counterPartyProfile.FacebookId;

            // load comments
            Comments = CommentHandler.getComments(transaction.TransactionId);
            foreach (Comment comment in Comments)
            {
                if (comment.UserId == UserId)
                {
                    comment.CommentByCurrentUser = true;
                }
                else
                {
                    comment.CommentByCurrentUser = false;
                }
            }
        }
コード例 #6
0
ファイル: Matchmaker.cs プロジェクト: hw3jung/Chanel
        /*
         * Given a new post, match it with the most appropriate post (if possible).
         *
         * Conditions
         * ----------
         *
         * If the new post was made by a buyer, then the matching post must have:
         *      -price less than or equal to that specified by buyer
         *      -book condition better than or equal to that specified by buyer
         *
         * If the new post was made by a seller, then the matching post must have:
         *      -price greater than or equal to that specified by seller
         *      -book condition worse than or equal to that specified by seller
         *
         */
        public static void Match(Post newPost)
        {
            if (!PostHandler.isPostAvailable(newPost.PostId))
            {
                return;
            }

            Post matchingPost = PostHandler.findMatchingPost(newPost);
            if (matchingPost != null)
            {
                int buyerPostId = -1;
                int sellerPostId = -1;

                int buyerUserId = -1;
                int sellerUserId = -1;

                int initialPrice;

                if (newPost.ActionBy == ActionBy.Buyer)
                {
                    buyerPostId = newPost.PostId;
                    sellerPostId = matchingPost.PostId;

                    buyerUserId = newPost.UserId;
                    sellerUserId = matchingPost.UserId;

                    initialPrice = matchingPost.Price;
                }
                else
                {
                    buyerPostId = matchingPost.PostId;
                    sellerPostId = newPost.PostId;

                    buyerUserId = matchingPost.UserId;
                    sellerUserId = newPost.UserId;

                    initialPrice = newPost.Price;
                }

                // Create transaction and transactionhistory for the matched buyer & seller
                Transaction newTransaction = new Transaction(
                    -1, // id doesnt matter here
                    newPost.TextBookId,
                    sellerUserId,
                    buyerUserId,
                    sellerPostId,
                    buyerPostId,
                    null,
                    null,
                    initialPrice,
                    0,
                    1,
                    0,
                    DateTime.Now,
                    DateTime.Now
                );

                PostHandler.updatePostState(newPost.PostId, 1);
                PostHandler.updatePostState(matchingPost.PostId, 1);

                int transactionId = TransactionHandler.CreateTransaction(newTransaction);
                newTransaction.TransactionId = transactionId;

                TransactionHandler.CreateTransactionHistory(transactionId, buyerUserId);
                TransactionHandler.CreateTransactionHistory(transactionId, sellerUserId);
            }
        }
コード例 #7
0
ファイル: TransactionHandler.cs プロジェクト: hw3jung/Chanel
        public static Transaction getTransaction(int transactionId)
        {
            Transaction transaction = null;

            DataAccess da = new DataAccess();
            DataTable dt = da.select(String.Format("TransactionId = '{0}'", transactionId), "Transactions", NumRows : 1);

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

                int TransactionId = Convert.ToInt32(row["TransactionId"]);
                int TextbookId = Convert.ToInt32(row["TextbookId"]);
                int SellerId = Convert.ToInt32(row["SellerId"]);
                int BuyerId = Convert.ToInt32(row["BuyerId"]);
                int SellerPostId = Convert.ToInt32(row["SellerPostId"]);
                int BuyerPostId = Convert.ToInt32(row["BuyerPostId"]);
                int? FinalPrice = row["FinalPrice"] is DBNull ? (int?)null : Convert.ToInt32(row["FinalPrice"]);
                int? ConfirmPrice = row["ConfirmPrice"] is DBNull ? (int?)null : Convert.ToInt32(row["ConfirmPrice"]);
                int InitialPrice = Convert.ToInt32(row["InitialPrice"]);
                Confirmed Confirmed = (Confirmed) Convert.ToInt32(row["Confirmed"]);
                int IsActive = Convert.ToInt32(row["IsActive"]);
                int IsDeleted = Convert.ToInt32(row["IsDeleted"]);
                DateTime CreatedDate = Convert.ToDateTime(row["CreatedDate"]);
                DateTime ModifiedDate = Convert.ToDateTime(row["ModifiedDate"]);

                transaction = new Transaction(
                    TransactionId,
                    TextbookId,
                    SellerId,
                    BuyerId,
                    SellerPostId,
                    BuyerPostId,
                    FinalPrice,
                    ConfirmPrice,
                    InitialPrice,
                    Confirmed,
                    IsActive,
                    IsDeleted,
                    CreatedDate,
                    ModifiedDate
                );
            }

            return transaction;
        }
コード例 #8
0
ファイル: TransactionHandler.cs プロジェクト: hw3jung/Chanel
        public static int CreateTransaction(Transaction transaction)
        {
            int transactionId = -1;

            try
            {
                DataAccess da = new DataAccess();

                Dictionary<string, object> Transaction = new Dictionary<string, object>();
                Transaction.Add("TextbookId", transaction.TextbookId);
                Transaction.Add("SellerId", transaction.SellerId);
                Transaction.Add("BuyerId", transaction.BuyerId);
                Transaction.Add("SellerPostId", transaction.SellerPostId);
                Transaction.Add("BuyerPostId", transaction.BuyerPostId);
                Transaction.Add("FinalPrice", transaction.FinalPrice == null ? (object)DBNull.Value : transaction.FinalPrice);
                Transaction.Add("InitialPrice", transaction.InitialPrice);
                Transaction.Add("Confirmed", transaction.Confirmed);
                Transaction.Add("IsActive", transaction.IsActive);
                Transaction.Add("IsDeleted", transaction.IsDeleted);
                Transaction.Add("CreatedDate", transaction.CreatedDate);
                Transaction.Add("ModifiedDate", transaction.ModifiedDate);

                transactionId = da.insert(Transaction, "Transactions");

                Dictionary<string, object> TransactionSeller = new Dictionary<string, object>();
                TransactionSeller.Add("TransactionId", transactionId);
                TransactionSeller.Add("UserId", transaction.SellerId);

                Dictionary<string, object> TransactionBuyer = new Dictionary<string, object>();
                TransactionBuyer.Add("TransactionId", transactionId);
                TransactionBuyer.Add("UserId", transaction.BuyerId);

                da.insert(TransactionBuyer, "TransactionHistory");
                da.insert(TransactionSeller, "TransactionHistory");

            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in adding a new transaction --- " + ex.Message + "          " + ex.StackTrace);
            }

            return transactionId;
        }
コード例 #9
0
ファイル: TransactionHandler.cs プロジェクト: hw3jung/Chanel
        public static bool ConfirmTransaction(Transaction transaction)
        {
            Dictionary<string, object> updateDictionary = new Dictionary<string, object>();

            if (transaction.FinalPrice != null && transaction.Confirmed == Confirmed.ByNone)
            {
                updateDictionary.Add("FinalPrice", (int)transaction.FinalPrice);

                Profile buyer = ProfileHandler.GetProfile(transaction.BuyerId);
                Profile seller = ProfileHandler.GetProfile(transaction.SellerId);

                Textbook book = TextbookHandler.getTextbook(transaction.TextbookId);
                if (transaction.CurrentUser == ActionBy.Buyer)
                {
                    updateDictionary.Add("Confirmed", (int)Confirmed.ByBuyer);
                    EmailUtility.SendEmail(
                        Convert.ToString(seller.Email),
                        Convert.ToString(seller.Name),
                        "Please confirm your transaction",
                        String.Format("Item: {0}<br/>{1} has confirmed a transaction with you!<br/>" +
                            "Please confirm it yourself to finalize the transaction.",
                            book.BookTitle,
                            buyer.Name)
                    );
                }
                else
                {
                    updateDictionary.Add("Confirmed", (int)Confirmed.BySeller);
                    EmailUtility.SendEmail(
                        Convert.ToString(buyer.Email),
                        Convert.ToString(buyer.Name),
                        "Please confirm your transaction",
                        String.Format("Item: {0}<br/>{1} has confirmed a transaction with you!<br/>" +
                            "Please confirm it yourself to finalize the transaction.",
                            book.BookTitle,
                            seller.Name)
                    );
                }
            }
            else if (transaction.FinalPrice != null)
            {
                updateDictionary.Add("ConfirmPrice", (int)transaction.FinalPrice);
                updateDictionary.Add("Confirmed", (int)Confirmed.ByBoth);
                updateDictionary.Add("IsActive", 0);

                PostHandler.updatePostState(transaction.SellerPostId, 0, 0);
                PostHandler.updatePostState(transaction.BuyerPostId, 0, 0);

                Profile buyer = ProfileHandler.GetProfile(transaction.BuyerId);
                Profile seller = ProfileHandler.GetProfile(transaction.SellerId);

                Textbook book = TextbookHandler.getTextbook(transaction.TextbookId);
                EmailUtility.SendEmail(
                    Convert.ToString(buyer.Email),
                    Convert.ToString(buyer.Name),
                    "Your transaction is now complete",
                    String.Format("Item: {0}<br/>Your transaction with {1} has finalized.<br/>" +
                        "Thank you for using BookSpade!",
                        book.BookTitle,
                        seller.Name)
                );

                EmailUtility.SendEmail(
                    Convert.ToString(seller.Email),
                    Convert.ToString(seller.Name),
                    "Your transaction is now complete",
                    String.Format("Item: {0}<br/>Your transaction with {1} has finalized.<br/>" +
                        "Thank you for using BookSpade!",
                        book.BookTitle,
                        buyer.Name)
                );
            }

            UpdateTransaction(transaction.TransactionId, updateDictionary);
            return true;
        }