Ejemplo n.º 1
0
        public decimal UpdateContract_ContainShipments(Contract contract, Shipment[] shipments, ContractDetail[] contractDetails)
        {
            decimal _result          = -1;
            var     shipmentDa       = new ShipmentDA();
            var     contractDetailDa = new ContractDetailDA();

            try
            {
                var shipmentsAdd  = shipments.Where(s => s.Id == 0).ToArray();
                var shipmentsEdit = shipments.Where(s => s.Id > 0).ToArray();
                var detailsAdd    = contractDetails.Where(cd => cd.Contract_Detail_Id == 0).ToArray();
                var detailsEdit   = contractDetails.Where(cd => cd.Contract_Detail_Id > 0).ToArray();
                using (var conn = new OracleConnection(Common.gConnectString))
                {
                    conn.Open();
                    using (var trans = conn.BeginTransaction())
                    {
                        _result = UpdateContract(contract, trans);

                        if (_result >= 0 && shipmentsAdd.Length > 0)
                        {
                            _result = shipmentDa.InsertShipments(shipmentsAdd, trans);
                        }
                        if (_result >= 0 && shipmentsEdit.Length > 0)
                        {
                            _result = shipmentDa.UpdateShipments(shipmentsEdit, trans);
                        }
                        if (_result >= 0 && detailsAdd.Length > 0)
                        {
                            _result = contractDetailDa.InsertContractDetail(detailsAdd, trans);
                        }
                        if (_result >= 0 && detailsEdit.Length > 0)
                        {
                            _result = contractDetailDa.UpdateContractDetail(detailsEdit, trans);
                        }
                        if (_result < 0)
                        {
                            trans.Rollback();
                        }
                        else
                        {
                            trans.Commit();
                        }
                    }
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                Common.log.Error(ex.ToString());
                _result = -1;
            }
            return(_result);
        }
Ejemplo n.º 2
0
        public decimal InsertContract_ContainShipments(Contract contract, Shipment[] shipments, ContractDetail[] contractDetails)
        {
            decimal _result          = -1;
            var     shipmentDa       = new ShipmentDA();
            var     contractDetailDa = new ContractDetailDA();

            try
            {
                using (var conn = new OracleConnection(Common.gConnectString))
                {
                    conn.Open();
                    using (var trans = conn.BeginTransaction())
                    {
                        _result = InsertContract(contract, trans);
                        if (_result >= 0 && shipments.Length > 0)
                        {
                            _result = shipmentDa.InsertShipments(shipments, trans);
                        }
                        if (_result >= 0 && contractDetails.Length > 0)
                        {
                            _result = contractDetailDa.InsertContractDetail(contractDetails, trans);
                        }
                        if (_result < 0)
                        {
                            trans.Rollback();
                        }
                        else
                        {
                            trans.Commit();
                        }
                    }
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                Common.log.Error(ex.ToString());
                _result = -1;
            }
            return(_result);
        }