Beispiel #1
0
        public static int createPost(Post newPost)
        {
            int id = -1;

            try
            {
                DataAccess da = new DataAccess();

                Dictionary<string, object> post = new Dictionary<string, object>();
                post.Add("UserId", newPost.UserId);
                post.Add("TextBookId", newPost.TextBookId);
                post.Add("ActionBy ", (int) newPost.ActionBy); // enum must be casted to int before we can store it in db
                post.Add("Price", newPost.Price);
                post.Add("BookCondition", (int) newPost.BookCondition); // enum must be casted to int before we can store it in db
                post.Add("IsTransacting", newPost.IsTransacting);
                post.Add("IsActive", 1);
                post.Add("IsDeleted", 0);
                post.Add("CreatedDate", DateTime.Now);
                post.Add("ModifiedDate", DateTime.Now);

                id = da.insert(post, "Posts");
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message + "    " + ex.StackTrace);
            }

            return id;
        }
Beispiel #2
0
        public static int createComment(Comment comment)
        {
            int id = -1;

            try
            {
                DataAccess da = new DataAccess();

                Dictionary<string, object> TransactionComment = new Dictionary<string, object>();
                TransactionComment.Add("UserId", comment.UserId);
                TransactionComment.Add("ActionBy", (int)comment.ActionBy);
                TransactionComment.Add("TransactionId ", comment.TransactionId);
                TransactionComment.Add("Comment", comment.comment);
                TransactionComment.Add("ReminderSent", 0);
                TransactionComment.Add("IsActive", 1);
                TransactionComment.Add("IsDeleted", 0);
                TransactionComment.Add("CreatedDate", DateTime.Now);
                TransactionComment.Add("ModifiedDate", DateTime.Now);

                id = da.insert(TransactionComment, "TransactionComments");
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message + "    " + ex.StackTrace);
            }

            return id;
        }
Beispiel #3
0
        public static int CreateProfile(string Name, string Email)
        {
            int id = -1;

            try
            {

                DataAccess DAL = new DataAccess();
                DataTable dt = DAL.select(String.Format("UserName = '******'", Email), "UserProfile", NumRows : 1);

                if (dt == null || dt.Rows.Count == 0)
                {
                    Dictionary<string, object> profile = new Dictionary<string, object>();
                    profile.Add("Name", Name);
                    profile.Add("Email", Email);
                    profile.Add("IsActive", 1);
                    profile.Add("IsDeleted", 0);
                    profile.Add("CreatedDate", DateTime.Now);
                    profile.Add("ModifiedDate", DateTime.Now);

                    id = DAL.insert(profile, "UserProfile");
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in adding a new course --- " + ex.Message);
            }

            return id;
        }
Beispiel #4
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;
        }
Beispiel #5
0
        public static int CreateCourse(string courseName)
        {
            int id = -1;

            try
            {
                DataAccess DAL = new DataAccess();
                DataTable dt = DAL.select(String.Format("CourseName = '{0}'", courseName), "CourseInfo", NumRows : 1);

                if (dt == null || dt.Rows.Count == 0)
                {
                    Dictionary<string, object> courseInfo = new Dictionary<string, object>();
                    courseInfo.Add("CourseName", courseName);
                    courseInfo.Add("Description", courseName);
                    courseInfo.Add("IsActive", 1);
                    courseInfo.Add("IsDeleted", 0);
                    courseInfo.Add("CreatedDate", DateTime.Now);
                    courseInfo.Add("ModifiedDate", 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;
        }
Beispiel #6
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 #7
0
        /// ** VALUES SET ** 
        /// After 14 day since a transaction has occured set the following:
        /// PostTable: IsActive = 0, IsTransacting = 0 [for each participant]
        /// Transaction Table: IsActive = 0, confirmed = 3
        /// 
        public static void AutoConfirmTransaction()
        {
            DataAccess da = new DataAccess();
            DataTable dt = da.ExecuteStoredProc("AutoConfirmTransaction");

            dt.AsEnumerable().ToList().ForEach(x =>
                AutoConfirmEmails(
                    Convert.ToString(x["BuyerEmail"]),
                    Convert.ToString(x["Buyer"]),
                    Convert.ToString(x["SellerEmail"]),
                    Convert.ToString(x["Seller"])
                    )
                );
        }
Beispiel #8
0
 public static void commentReminderMail()
 {
     DataAccess da = new DataAccess();
     DataTable dt = da.ExecuteStoredProc("getUsersToEmail");
     dt.AsEnumerable().ToList().ForEach(x =>
         EmailUtility.SendEmail(
             Convert.ToString(x["UserName"]),
             Convert.ToString(x["DisplayName"]),
             String.Format("{0} has sent you a message! ",
                 Convert.ToString(x["Commentor_DisplayName"])),
             String.Format("{0} has sent you a message: <br/> '{1}'",
                 Convert.ToString(x["Commentor_DisplayName"]),
                 Convert.ToString(x["Comment"]))
         )
     );
 }
Beispiel #9
0
        //Confirm Validation -> Checks to see if the user has confirmed using the token
        //If a user that hasn't confirmed tries to log in we will send them an incorrect username or password error
        public static bool ConfirmValidation(string Email)
        {
            try
            {
                var DAL = new DataAccess();
                var dt = DAL.select(String.Format("UserName = '******' AND IsValid = '1' ", Email), "UserProfile", NumRows: 1);

                return dt.Rows.Count > 0;

            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving the user profile --- " + ex.Message);
            }

            return false; //uh oh ..
        }
Beispiel #10
0
        public static IEnumerable<Comment> getComments(int TransactionId)
        {
            DataAccess da = new DataAccess();
            DataTable dt = da.select(String.Format("TransactionId = '{0}' AND IsActive = 1 AND IsDeleted = 0", TransactionId), "TransactionComments");
            IEnumerable<Comment> comments = dt.AsEnumerable().Select(
                                                        x => new Comment(
                                                            Convert.ToInt32(x["CommentId"]),
                                                            Convert.ToString(x["Comment"]),
                                                            Convert.ToInt32(x["UserId"]),
                                                            (ActionBy)Convert.ToInt32(x["ActionBy"]),
                                                            Convert.ToInt32(x["TransactionId"]),
                                                            Convert.ToInt32(x["IsActive"]),
                                                            Convert.ToInt32(x["IsDeleted"]),
                                                            Convert.ToDateTime(x["CreatedDate"]),
                                                            Convert.ToDateTime(x["ModifiedDate"]))).OrderBy(x => x.CreatedDate).ToList();

            return comments;
        }
Beispiel #11
0
        //in B.S. UserName == Email
        public static string GetFacebookId(int userId)
        {
            string facebookId = null;

            try
            {
                DataAccess DAL = new DataAccess();
                DataTable dt = DAL.select(String.Format("UserId = '{0}'", userId), "UserProfile", NumRows: 1, ColumnNames: new string[] { "FacebookId" });

                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];
                    facebookId = row["FacebookId"] is DBNull ? null : Convert.ToString(row["FacebookId"]);
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving the facebook id for user --- " + ex.Message);
            }

            return facebookId;
        }
Beispiel #12
0
        public static Course getCourse(int courseId)
        {
            Course course = null;

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

                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];
                    string CourseName = Convert.ToString(row["CourseName"]);
                    string Description = Convert.ToString(row["Description"]);
                    int IsActive = Convert.ToInt32(row["IsActive"]);
                    int IsDeleted = Convert.ToInt32(row["IsDeleted"]);
                    DateTime CreatedDate = Convert.ToDateTime(row["CreatedDate"]);
                    DateTime ModifiedDate = Convert.ToDateTime(row["ModifiedDate"]);

                    course = new Course(
                        courseId,
                        CourseName,
                        Description,
                        IsActive,
                        IsDeleted,
                        CreatedDate,
                        ModifiedDate
                    );
                }

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

            return course;
        }
Beispiel #13
0
        public static bool isPostAvailable(int postId)
        {
            bool availableForMatching = false;

            try
            {
                DataAccess da = new DataAccess();
                DataTable dt = da.select(String.Format("PostId = '{0}' AND IsDeleted = 0", postId), "Posts", NumRows: 1);

                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];
                    int isTransacting = Convert.ToInt32(row["IsTransacting"]);
                    int isActive = Convert.ToInt32(row["IsActive"]);

                    availableForMatching = isTransacting == 0 && isActive == 1;
                }
            }
            catch (Exception e)
            {
                Console.Write("ERROR: Could not check post state with the given post id --- " + e.Message);
            }

            return availableForMatching;
        }
Beispiel #14
0
        public static Post getPost(int postId)
        {
            Post post = null;

            try
            {
                DataAccess da = new DataAccess();
                DataTable dt = da.select(String.Format("PostId = '{0}' AND IsDeleted = 0", postId), "Posts", NumRows : 1);

                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];
                    int profileId = Convert.ToInt32(row["UserId"]);
                    int textbookId = Convert.ToInt32(row["TextBookId"]);
                    ActionBy actionBy = (ActionBy)Convert.ToInt32(row["ActionBy"]);
                    int price = Convert.ToInt32(row["Price"]);
                    BookCondition bookCondition = (BookCondition)Convert.ToInt32(row["BookCondition"]);
                    int isTransacting = Convert.ToInt32(row["IsTransacting"]);
                    int isActive = Convert.ToInt32(row["IsActive"]);
                    int isDeleted = Convert.ToInt32(row["IsDeleted"]);
                    DateTime createdDate = (DateTime)row["CreatedDate"];
                    DateTime modifiedDate = (DateTime)row["ModifiedDate"];

                    post = new Post(
                        postId,
                        profileId,
                        textbookId,
                        actionBy,
                        price,
                        bookCondition,
                        isTransacting,
                        isActive,
                        isDeleted,
                        createdDate,
                        modifiedDate
                    );
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message + "   " + ex.StackTrace);
            }

            return post;
        }
Beispiel #15
0
        public static bool updatePostState(int postId, int isTransacting, int? isActive = null)
        {
            bool success = true;

            try
            {
                Dictionary<string, object> updateDict = new Dictionary<string, object>();
                updateDict.Add("IsTransacting", isTransacting);

                if (isActive != null)
                {
                    updateDict.Add("IsActive", isActive);
                }

                DataAccess da = new DataAccess();
                da.update("Posts", String.Format("PostId = {0}", postId), updateDict);
            }
            catch (Exception e)
            {
                Console.Write("ERROR: Could not update post state with the given post id --- " + e.Message);
                success = false;
            }

            return success;
        }
Beispiel #16
0
        public static string getCourseName(int courseId)
        {
            string courseName = null;

            try
            {
                DataAccess da = new DataAccess();
                DataTable dt = da.select(String.Format("CourseId = '{0}' AND IsActive = 1 AND IsDeleted = 0", courseId), "CourseInfo", NumRows: 1, ColumnNames: new string[] {"CourseName"});

                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];
                    courseName = Convert.ToString(row["CourseName"]);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message + "   " + ex.StackTrace);
            }

            return courseName;
        }
Beispiel #17
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 #18
0
        public static Post findMatchingPost(Post post)
        {
            Post matchingPost = null;

            try
            {
                var counterparty = post.ActionBy == ActionBy.Buyer ? ActionBy.Seller : ActionBy.Buyer;

                string query = String.Format("UserId <> {0} AND TextBookId = {1} AND ActionBy = {2} " +
                    "AND IsTransacting = 0 AND IsActive = 1 AND IsDeleted = 0",
                    post.UserId,
                    post.TextBookId,
                    (int)counterparty
                );

                List<SortColumn> sortColumns = new List<SortColumn>();
                if (post.ActionBy == ActionBy.Buyer) //buyer
                {
                    query += String.Format("AND Price <= {0} AND BookCondition >= {1}",
                        post.Price,
                        (int)post.BookCondition
                    );

                    sortColumns.Add(new SortColumn("Price", "ASC"));
                }
                else //seller
                {
                    query += String.Format("AND Price >= {0} AND BookCondition <= {1}",
                        post.Price,
                        (int)post.BookCondition
                    );

                    sortColumns.Add(new SortColumn("Price", "DESC"));
                }

                DataAccess da = new DataAccess();
                DataTable dt = da.select(query, "Posts", NumRows : 1, SortColumns : sortColumns);

                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];
                    int postId = Convert.ToInt32(row["PostId"]);
                    int profileId = Convert.ToInt32(row["UserId"]);
                    int textBookId = Convert.ToInt32(row["TextBookId"]);
                    ActionBy actionBy = (ActionBy)Convert.ToInt32(row["ActionBy"]);
                    int price = Convert.ToInt32(row["Price"]);
                    BookCondition bookCondition = (BookCondition)Convert.ToInt32(row["BookCondition"]);
                    int isTransacting = Convert.ToInt32(row["IsTransacting"]);
                    int isActive = Convert.ToInt32(row["IsActive"]);
                    int isDeleted = Convert.ToInt32(row["IsDeleted"]);
                    DateTime createdDate = (DateTime)row["CreatedDate"];
                    DateTime modifiedDate = (DateTime)row["ModifiedDate"];

                    matchingPost = new Post(
                        postId,
                        profileId,
                        textBookId,
                        actionBy,
                        price,
                        bookCondition,
                        isTransacting,
                        isActive,
                        isDeleted,
                        createdDate,
                        modifiedDate
                    );
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message + "   " + ex.StackTrace);
            }

            return matchingPost;
        }
Beispiel #19
0
        private static int CreateForbiddenMatch(int PostId, int MatchedPostId)
        {
            DataAccess da = new DataAccess();

            Dictionary<string, object> CancelledTransaction = new Dictionary<string, object>();
            CancelledTransaction.Add("PostId", PostId);
            CancelledTransaction.Add("MatchedPostId", MatchedPostId);

            return da.insert(CancelledTransaction, "CancelledTransactions");
        }
Beispiel #20
0
        //in B.S. UserName == Email
        public static int GetProfileId(string Email)
        {
            int profileId = -1;

            try
            {
                DataAccess DAL = new DataAccess();
                DataTable dt = DAL.select(String.Format("UserName = '******'", Email), "UserProfile", NumRows : 1);

                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];
                    profileId = Convert.ToInt32(row["UserId"]);
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving the user profile --- " + ex.Message);
            }

            return profileId;
        }
Beispiel #21
0
        public static IEnumerable<Transaction> getUserTransactionHistory(int UserId)
        {
            DataAccess da = new DataAccess();
            List<int> transactionIds = da.select(String.Format("UserId = '{0}'", UserId), "TransactionHistory").AsEnumerable().Select(x => (int)x["TransactionId"]).ToList();
            string Ids = string.Join(",", transactionIds);
            DataTable dt = da.select(String.Format("TransactionId IN ({0})", Ids), "Transactions");
            IEnumerable<Transaction>  transactions = dt.AsEnumerable().Select(
                                                        x => new Transaction(
                                                            Convert.ToInt32(x["TransactionId"]),
                                                            Convert.ToInt32(x["TextbookId"]),
                                                            Convert.ToInt32(x["SellerId"]),
                                                            Convert.ToInt32(x["BuyerId"]),
                                                            Convert.ToInt32(x["SellerPostId"]),
                                                            Convert.ToInt32(x["BuyerPostId"]),
                                                            x["FinalPrice"] is DBNull ? (int?) null : Convert.ToInt32(x["FinalPrice"]),
                                                            x["ConfirmPrice"] is DBNull ? (int?)null : Convert.ToInt32(x["ConfirmPrice"]),
                                                            Convert.ToInt32(x["InitialPrice"]),
                                                            (Confirmed) Convert.ToInt32(x["Confirmed"]),
                                                            Convert.ToInt32(x["IsActive"]),
                                                            Convert.ToInt32(x["IsDeleted"]),
                                                            Convert.ToDateTime(x["CreatedDate"]),
                                                            Convert.ToDateTime(x["ModifiedDate"]))).ToList();

            return transactions;
        }
Beispiel #22
0
 public static void UpdateTransaction(int transactionId, Dictionary<string, object> updateDictionary)
 {
     DataAccess da = new DataAccess();
     da.update("Transactions", String.Format("TransactionId = {0}", transactionId), updateDictionary);
 }
Beispiel #23
0
        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;
        }
Beispiel #24
0
        public static int CreateTransactionHistory(int transactionId, int userId)
        {
            int transactionHistoryId = -1;

            try
            {
                DataAccess da = new DataAccess();

                Dictionary<string, object> transactionHistory = new Dictionary<string, object>();
                transactionHistory.Add("TransactionId", transactionId);
                transactionHistory.Add("UserId", userId);

                transactionHistoryId = da.insert(transactionHistory, "TransactionHistory");
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in adding a new transaction --- " + ex.Message + "          " + ex.StackTrace);
            }

            return transactionHistoryId;
        }
Beispiel #25
0
        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;
        }
Beispiel #26
0
        //User clicked on link
        //We shall update the database to validate his/her account using the provided token
        public static Profile ValidateProfile(Guid Token)
        {
            Profile profile = null;

            try
            {
                var DAL = new DataAccess();
                var dt = DAL.select(String.Format("ValidationToken = '{0}'", Token), "UserProfile", NumRows: 1);

                if (dt != null && dt.Rows.Count > 0)
                {
                    var updateDictionary = new Dictionary<string, object>();

                    updateDictionary.Add("IsValid", true);

                    DAL.update("UserProfile", "ValidationToken = '{0}'", updateDictionary);

                    var row = dt.Rows[0];
                    var UserName = Convert.ToString(row["UserName"]);
                    var profileId = Convert.ToInt32(row["UserId"]);
                    var displayName = Convert.ToString(row["DisplayName"]);
                    var facebookId = row["FacebookId"] is DBNull ? null : Convert.ToString(row["FacebookId"]);
                    var facebookLink = row["FacebookLink"] is DBNull ? null : Convert.ToString(row["FacebookLink"]);

                    profile = new Profile(profileId, displayName, UserName, facebookId, facebookLink);
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving the user profile --- " + ex.Message);
            }

            return profile;
        }
Beispiel #27
0
        public static Profile GetProfile(int userId)
        {
            Profile profile = null;

            try
            {
                DataAccess DAL = new DataAccess();
                DataTable dt = DAL.select(String.Format("UserId = '{0}'", userId), "UserProfile", NumRows : 1);

                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];
                    string name = Convert.ToString(row["DisplayName"]);
                    string email = Convert.ToString(row["UserName"]);
                    string facebookId = row["FacebookId"] is DBNull ? null : Convert.ToString(row["FacebookId"]);
                    string facebookLink = row["FacebookLink"] is DBNull ? null : Convert.ToString(row["FacebookLink"]);

                    profile = new Profile(userId, name, email, facebookId, facebookLink);
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving the user profile --- " + ex.Message);
            }

            return profile;
        }