Ejemplo n.º 1
0
        /// <summary>
        /// Created by Justin Pennington 2015/02/25
        /// Adds a SupplierFeedbackRecord to the database
        /// </summary>
        /// <param name="newFeedbackRecord">Contains values to be added to the database</param>
        /// <returns>rowsAffected (int)</returns>
        public static int AddSupplierFeedbackRecord(SupplierFeedbackRecord newFeedbackRecord)
        {
            //Connect To Database
            var conn         = DatabaseConnection.GetDatabaseConnection();
            var cmdText      = "spInsertSupplierFeedbackRecord";
            var cmd          = new SqlCommand(cmdText, conn);
            var rowsAffected = 0;

            cmd.CommandType = CommandType.StoredProcedure;

            //Set up Parameters For the Stored Procedure
            cmd.Parameters.AddWithValue("@SupplierID", newFeedbackRecord.SupplierID);
            cmd.Parameters.AddWithValue("@EmployeeID", newFeedbackRecord.EmployeeID);
            cmd.Parameters.AddWithValue("@Rating", newFeedbackRecord.Rating);
            cmd.Parameters.AddWithValue("@Notes", newFeedbackRecord.RatingNotes);

            try
            {
                conn.Open();
                rowsAffected = cmd.ExecuteNonQuery();
                if (rowsAffected == 0)
                {
                    throw new ApplicationException("Concurrency Violation");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return(rowsAffected);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Created by Justin Pennington 2015/02/25
        /// Deletes a SupplierFeedbackRecord from the database (no archive setting as of 2015/02/25)
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="supplierFeedback">A Supplier feedback record Object that contain all the information to be deleted</param>
        /// <exception cref="SQLException">Delete Fails</exception>
        /// <returns>rowsAffected (int)</returns>
        public static int DeleteSupplierFeedbackRecord(SupplierFeedbackRecord supplierFeedback)
        {
            var conn         = DatabaseConnection.GetDatabaseConnection();
            var cmdText      = "spDeleteSupplierFeedbackRecord";
            var cmd          = new SqlCommand(cmdText, conn);
            var rowsAffected = 0;

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@RatingID", supplierFeedback.RatingID);
            cmd.Parameters.AddWithValue("@SupplierID", supplierFeedback.SupplierID);
            cmd.Parameters.AddWithValue("@EmployeeID", supplierFeedback.EmployeeID);
            cmd.Parameters.AddWithValue("@Rating", supplierFeedback.Rating);
            cmd.Parameters.AddWithValue("@Notes", supplierFeedback.RatingNotes);
            try
            {
                conn.Open();
                rowsAffected = cmd.ExecuteNonQuery();
                if (rowsAffected == 0)
                {
                    throw new ApplicationException("Concurrency Violation");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return(rowsAffected);  // needs to be rows affected
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Created by Justin Pennington 2015/02/25
        /// Retrieves a SupplierFeedbackRecord list from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <exception cref="SQLException">Insert Fails</exception>
        /// <returns>List of SupplierFeedbackRecord</returns>
        public static List <SupplierFeedbackRecord> GetSupplierFeedbackRecordList()
        {
            var recordList = new List <SupplierFeedbackRecord>();

            // set up the database call
            var    conn    = DatabaseConnection.GetDatabaseConnection();
            string cmdText = "spSelectAllSupplierFeedbackRecord";
            var    cmd     = new SqlCommand(cmdText, conn);

            try
            {
                conn.Open();
                var reader = cmd.ExecuteReader();
                if (reader.HasRows == true)
                {
                    while (reader.Read())
                    {
                        var currentRecord = new SupplierFeedbackRecord();

                        currentRecord.RatingID    = reader.GetInt32(0);
                        currentRecord.SupplierID  = reader.GetInt32(1);
                        currentRecord.EmployeeID  = reader.GetInt32(2);
                        currentRecord.Rating      = reader.GetInt32(3);
                        currentRecord.RatingNotes = reader.GetString(4);
                        recordList.Add(currentRecord);
                    }
                }
                else
                {
                    var ax = new ApplicationException("Data not found!");
                    throw ax;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return(recordList);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Created by Justin Pennington 2015/02/25
        /// Retrieves a SupplierFeedbackRecord from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ratingID">A rating ID pulled from an object</param>
        /// <exception cref="SQLException">Insert Fails</exception>
        /// <returns>SupplierFeedbackRecord</returns>
        public static SupplierFeedbackRecord GetSupplierFeedbackRecord(String ratingID)
        {
            var theRecord = new SupplierFeedbackRecord();
            // set up the database call
            var    conn    = DatabaseConnection.GetDatabaseConnection();
            string cmdText = "spSelectSupplierFeedbackRecord";
            var    cmd     = new SqlCommand(cmdText, conn);

            cmd.Parameters.AddWithValue("@RatingID", ratingID);
            try
            {
                conn.Open();
                var reader = cmd.ExecuteReader();
                if (reader.HasRows == true)
                {
                    theRecord.RatingID    = reader.GetInt32(0);
                    theRecord.SupplierID  = reader.GetInt32(1);
                    theRecord.EmployeeID  = reader.GetInt32(2);
                    theRecord.Rating      = reader.GetInt32(3);
                    theRecord.RatingNotes = reader.GetString(4);
                }
                else
                {
                    var ax = new ApplicationException("Data not found!");
                    throw ax;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return(theRecord);
        }