public static int createBid(Bid bid) { int bidID = -1; DataAccessLayer DAL = new DataAccessLayer(); DataTable bidDupPrices = DAL.select(String.Format("BidPrice = '{0}' AND PostID = '{1}'", bid.BidPrice, bid.PostID), "Bids"); if (bidDupPrices.Rows.Count > 0) { return bidID; } Dictionary<string, string> Bid = new Dictionary<string, string>(); Bid.Add("BidPrice", Convert.ToString(bid.BidPrice)); Bid.Add("PostID", Convert.ToString(bid.PostID)); Bid.Add("BidderID", Convert.ToString(bid.BidderID)); Bid.Add("viaEmail", Convert.ToString(bid.BidviaEmail)); Bid.Add("IsActive", Convert.ToString(true)); Bid.Add("IsDeleted", Convert.ToString(false)); Bid.Add("CreatedDate", Convert.ToString(DateTime.Now)); Bid.Add("ModifiedDate", Convert.ToString(DateTime.Now)); bidID = DAL.insert(Bid, "Bids"); return bidID; }
public static int AddUser(UserProfile elm) { int id = -1; try { DataAccessLayer DAL = new DataAccessLayer(); DataTable dt = DAL.select(String.Format("FacebookID = '{0}'", elm.FacebookID), "UserProfile"); if (dt == null ||dt.Rows.Count == 0) { Dictionary<string, string> Profile = new Dictionary<string, string>(); Profile.Add("FacebookID", elm.FacebookID); Profile.Add("Name", elm.Name); Profile.Add("Email", elm.Email); Profile.Add("FacebookProfileLink", elm.FacebookProfileLink); Profile.Add("Gender", elm.Gender); Profile.Add("IsActive", "1"); Profile.Add("IsDeleted", "0"); Profile.Add("CreatedDate", Convert.ToString(DateTime.Now)); Profile.Add("ModifiedDate", Convert.ToString(DateTime.Now)); id = DAL.insert(Profile, "UserProfile"); } } catch (Exception ex) { Console.Write("ERROR: An error occured in adding a new user --- " + ex.Message); } return id; }
public static int insert(Post newPost) { int id = -1; try { DataAccessLayer DAL = new DataAccessLayer(); // DataTable dt = DAL.select(String.Format("ProfileID = '{0}' AND TextBookID = '{1}' AND IsBuy = '{2}'", newPost.ProfileID, newPost.TextBookID, newPost.IsBuy), "Posts"); // if (dt == null || dt.Rows.Count == 0) // { Dictionary<string, string> post = new Dictionary<string, string>(); post.Add("ProfileID", Convert.ToString(newPost.ProfileID)); post.Add("TextBookID", Convert.ToString(newPost.TextBookID)); post.Add("IsBuy", Convert.ToString(newPost.IsBuy)); post.Add("Price", Convert.ToString(newPost.Price)); post.Add("viaEmail", Convert.ToString(newPost.viaEmail)); post.Add("BookCondition", newPost.Condition); post.Add("ExpiryDate", Convert.ToString(newPost.ExpiryDate)); post.Add("IsNegotiable", Convert.ToString(newPost.IsNegotiable)); post.Add("IsActive", "1"); post.Add("IsDeleted", "0"); post.Add("CreatedDate", Convert.ToString(DateTime.Now)); post.Add("ModifiedDate", Convert.ToString(DateTime.Now)); id = DAL.insert(post, "Posts"); // } } catch (Exception ex) { Console.Write("ERROR: An error occured in adding a new post --- " + ex.Message); } return id; }
public bool InsertStatus(DemoModel Status) { DataAccessLayer dal = new DataAccessLayer(); bool Success = true; try { /* Testing Insert */ Dictionary<string, string> dict = new Dictionary<string,string>(); dict.Add("StatusName", Status.StatusName); // no need to add statusID, as that column is an identity column dal.insert(dict, "TransactionStatus"); /* Testing Select */ DataTable dt = new DataTable(); dt = dal.select("StatusName = 'a'", "TransactionStatus"); foreach (DataRow row in dt.Rows) // Loop over the rows. { foreach (var col in row.ItemArray) { Debug.Write(col); } Debug.Write('\n'); } /* Testing Update */ Dictionary<string, string> d = new Dictionary<string, string>(); d.Add("StatusName", "'asma_rox'"); dal.update("TransactionStatus", "StatusName = 'asma_sux'", d); /* Manually go into SQL Server to see if the row is correctly updated */ /* Testing Delete */ dal.delete("StatusName = 'johnny'", "TransactionStatus"); /* now the db should not contain an entry with StatusName = 'johnny' */ } catch (Exception) { Success = false; } return Success; }
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; }
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; }