Esempio n. 1
0
        public int Destroy(int jobId)
        {
            int    result      = 0;
            string textCommand = "DELETE FROM tbl_Jobs WHERE JobId = @JobId";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(textCommand, connection);

                command.Parameters.AddWithValue("@JobId", jobId);

                connection.Open();

                result = command.ExecuteNonQuery();

                connection.Close();
            }

            if (result > 0)
            {
                List <Charge> charges = new ChargeCRUD().GetChargesByJobId(jobId);

                if (charges.Count > 0)
                {
                    foreach (Charge charge in charges)
                    {
                        new ChargeCRUD().Destroy(jobId, charge.ChargeId);
                    }
                }
            }

            return(result);
        }
Esempio n. 2
0
        public int Destroy(int jobId)
        {
            int    result      = 0;
            string textCommand = "DELETE FROM tbl_Jobs WHERE JobId = @JobId";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(textCommand, connection);

                command.Parameters.AddWithValue("@JobId", jobId);

                connection.Open();

                result = command.ExecuteNonQuery();

                connection.Close();
            }

            if (result > 0)
            {
                // delete charges
                List <Charge> charges = new ChargeCRUD().GetChargesByJobId(jobId);

                if (charges.Count > 0)
                {
                    foreach (Charge charge in charges)
                    {
                        new ChargeCRUD().Destroy(jobId, charge.ChargeId);
                    }
                }

                // remove orders
                List <Order> orders = new OrderCRUD().GetOrders().Where(x => x.JobId == jobId).ToList();

                if (orders.Count > 0)
                {
                    foreach (Order order in orders)
                    {
                        order.JobId = 0;
                        new OrderCRUD().Update(order);
                    }
                }

                // remove invoices
                List <Invoice> invoices = new InvoiceCRUD().GetInvoicesByJobId(jobId);

                if (invoices.Count > 0)
                {
                    foreach (Invoice invoice in invoices)
                    {
                        invoice.JobId = 0;
                        new InvoiceCRUD().Update(invoice);
                    }
                }

                // remove work periods
                List <WorkPeriod> workPeriods = new WorkPeriodCRUD().GetWorkPeriodsByJobId(jobId);

                if (workPeriods.Count > 0)
                {
                    foreach (WorkPeriod workPeriod in workPeriods)
                    {
                        workPeriod.JobId = 0;
                        new WorkPeriodCRUD().Update(workPeriod);
                    }
                }
            }

            return(result);
        }