public void Borrow(Borrow borrow) { bool isNotValid = borrow.BookID <= 0 || borrow.AccountID <= 0; if (isNotValid) { throw new NotImplementedException(); } Queue <object> parameters = new Queue <object>(); parameters.Enqueue(new MySqlParameter("@BookId", borrow.BookID)); parameters.Enqueue(new MySqlParameter("@AccountId", borrow.AccountID)); // have to explicitly set to date type MySqlParameter publishedParameter1 = new MySqlParameter("@Borrowed", borrow.Borrowed); publishedParameter1.DbType = DbType.Date; MySqlParameter publishedParameter2 = new MySqlParameter("@Returned", DateTime.MinValue); publishedParameter2.DbType = DbType.Date; parameters.Enqueue(publishedParameter1); parameters.Enqueue(publishedParameter2); string query = "INSERT INTO tblBorrow ( BookId, AccountId, Borrowed, Returned ) VALUES (@BookId, @AccountId, @Borrowed,@Returned)"; DBHelper.ExecuteQuery(query, parameters); }
public void Add(Account account) { bool isNotValid = string.IsNullOrEmpty(account.FullName) || string.IsNullOrEmpty(account.Username) || string.IsNullOrEmpty(account.Password); if (isNotValid) { throw new NotImplementedException(); } #region setParameters Queue <object> parameters = new Queue <object>(); parameters.Enqueue(new OleDbParameter("@FullName", account.FullName)); parameters.Enqueue(new OleDbParameter("@Address", account.Address)); parameters.Enqueue(new OleDbParameter("@PhoneNumber", account.PhoneNumber)); // have to explicitly set to date type OleDbParameter publishedParameter = new OleDbParameter("@Opened", account.Opened); publishedParameter.OleDbType = OleDbType.Date; parameters.Enqueue(publishedParameter); parameters.Enqueue(new OleDbParameter("@Level", account.AccountLevel)); parameters.Enqueue(new OleDbParameter("@Username", account.Username)); string salt = AuthHelper.CreateSalt(32); string password = AuthHelper.CreatePasswordHash(account.Password, salt); parameters.Enqueue(new OleDbParameter("@Password", password)); parameters.Enqueue(new OleDbParameter("@Salt", salt)); #endregion string query = "INSERT INTO tblAccount ( Fullname, Address, PhoneNumber, Opened, [Level], Username, [Password], Salt ) VALUES (@FullName, @Address, @PhoneNumber, @Opened, @Level, @Username, @Password, @Salt)"; DBHelper.ExecuteQuery(query, parameters); }
public void Borrow(Borrow borrow) { bool isNotValid = borrow.BookID <= 0 || borrow.AccountID <= 0; if (isNotValid) { throw new NotImplementedException(); } Queue <object> parameters = new Queue <object>(); parameters.Enqueue(new OleDbParameter("@BookId", borrow.BookID)); parameters.Enqueue(new OleDbParameter("@AccountId", borrow.AccountID)); // have to explicitly set to date type OleDbParameter publishedParameter = new OleDbParameter("@Borrowed", borrow.Borrowed); publishedParameter.OleDbType = OleDbType.Date; parameters.Enqueue(publishedParameter); string query = "INSERT INTO tblBorrow ( BookId, AccountId, Borrowed ) VALUES (@BookId, @AccountId, @Borrowed)"; DBHelper.ExecuteQuery(query, parameters); }
/// <summary> /// Add book to Table Book /// </summary> /// <param name="book">Book to Add</param> public void Add(Book book) { bool isNotValid = string.IsNullOrEmpty(book.Title); if (isNotValid) { throw new NotImplementedException(); } Queue <object> parameters = new Queue <object>(); parameters.Enqueue(new OleDbParameter("@Title", book.Title)); parameters.Enqueue(new OleDbParameter("@Author", book.Author)); parameters.Enqueue(new OleDbParameter("@Publisher", book.Publisher)); // have to explicitly set to date type OleDbParameter publishedParameter = new OleDbParameter("@PublishedDate", book.PublishedDate); publishedParameter.OleDbType = OleDbType.Date; parameters.Enqueue(publishedParameter); string query = "INSERT INTO tblBook ( Title, Author, Publisher, PublishedDate ) VALUES (@Title, @Author, @Publisher, @PublishedDate)"; DBHelper.ExecuteQuery(query, parameters); }