Beispiel #1
0
        /// <summary>
        /// Updates the status of the given rental
        /// </summary>
        /// <param name="transactionId">the rental transaction id</param>
        /// <param name="status"> the status </param>
        /// <param name="employeeId">the employee updating the rental</param>
        /// <param name="condition">the condition of the rental</param>
        /// <returns>the rows affected or an error if something goes wrong on the database</returns>
        public int UpdateStatus(int transactionId, string status, int employeeId, string condition)
        {
            var rowsEffected = 0;

            var statusId = RentalItem.GetStatusId(status);

            try
            {
                var conn = DbConnection.GetConnection();
                using (conn)
                {
                    conn.Open();
                    using (var transaction = conn.BeginTransaction())
                    {
                        var query =
                            "insert into status_history values (@transactionId, @statusID, @updateDateTime, @employeeID, @condition)";

                        using (var cmd = new MySqlCommand(query, conn))
                        {
                            cmd.Transaction = transaction;
                            cmd.Parameters.AddWithValue("@statusID", statusId);
                            cmd.Parameters.AddWithValue("@transactionId", transactionId);
                            cmd.Parameters.AddWithValue("@updateDateTime", DateTime.Now);
                            cmd.Parameters.AddWithValue("@employeeID", employeeId);
                            cmd.Parameters.AddWithValue("@condition", condition);

                            if (cmd.ExecuteNonQuery() != 1)
                            {
                                transaction.Rollback();
                            }

                            if (statusId == 2)
                            {
                                updateInventoryItemForShippedStatus(transactionId, cmd, transaction);
                                updateCondition(transactionId, cmd, transaction, condition);
                            }

                            if (statusId == 4)
                            {
                                insertIntoReturnConditionTable(transactionId, cmd, transaction, condition);
                                updateInventoryItemForReturnedStatus(transactionId, cmd, transaction,
                                                                     condition);
                            }

                            transaction.Commit();
                        }
                        conn.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(rowsEffected);
        }
Beispiel #2
0
 public void TestGetPossibleStatusIdWithReturned()
 {
     Assert.AreEqual(4, RentalItem.GetStatusId("Returned"));
 }
Beispiel #3
0
 public void TestGetPossibleStatusIdWithShipped()
 {
     Assert.AreEqual(2, RentalItem.GetStatusId("Shipped"));
 }
Beispiel #4
0
 public void TestGetPossibleStatusIdWithOrdered()
 {
     Assert.AreEqual(1, RentalItem.GetStatusId("Ordered"));
 }