Пример #1
0
        /// <summary>
        /// Get the borrower with the supplied PersonId from the database.
        /// </summary>
        /// <param name="borrower">A variable of typ Borrower. Will be set to a new instance or null if
        /// no borrower with given id was found.</param>
        /// <param name="PersonId">The id of the borrower as a string.</param>
        /// <returns>Returns true if no errors occured.</returns>
        public static bool GetBorrower(out Borrower borrower, string PersonId)
        {
            borrower = null;

            SqlCommand command = new SqlCommand("SELECT * from BORROWER WHERE PersonId = @PersonId");
            command.Parameters.AddWithValue("@PersonId", PersonId);

            List<Borrower> borrowerList;

            bool result = GetBorrowers(out borrowerList, command);

            if (borrowerList.Count > 0)
            {
                borrower = borrowerList[0];
            }

            return result;
        }
Пример #2
0
        /// <summary>
        /// Update or insert a borrower.
        /// </summary>
        /// <param name="borrower">The Borrower to upsert.</param>
        /// <returns>Returns true if upsert failed or an error occured.</returns>
        public static bool Upsert(Borrower borrower)
        {
            try
            {
                using (SqlConnection connection = HelperFunctions.GetConnection())
                {
                    connection.Open();
                    // Update BOOK
                    using (SqlCommand command = new SqlCommand("EXEC UpsertBorrower @PersonId, @FirstName, @LastName, @Address, @Telno, @CategoryId"))
                    {
                        command.Connection = connection;
                        command.Parameters.AddWithValue("@PersonId", borrower.PersonId);
                        command.Parameters.AddWithValue("@FirstName", HelperFunctions.ValueOrDBNull(borrower.FirstName));
                        command.Parameters.AddWithValue("@LastName", HelperFunctions.ValueOrDBNull(borrower.LastName));
                        command.Parameters.AddWithValue("@Address", HelperFunctions.ValueOrDBNull(borrower.Adress));
                        command.Parameters.AddWithValue("@Telno", HelperFunctions.ValueOrDBNull(borrower.TelNo));
                        command.Parameters.AddWithValue("@CategoryId", HelperFunctions.ValueOrDBNull(borrower.CategoryId));

                        if (command.ExecuteNonQuery() != 1)
                        {
                            return false;
                        }
                    }
                }
            }
            catch(Exception)
            {
                return false;
            }

            return true;
        }