Exemplo n.º 1
0
 // copy all rows from a List of SOAP Contracts to a List of serialized data objects
 // links:
 //  docLink: http://sql2x.org/documentationLink/1c6c6b9c-e201-4590-8c69-d38a0ad2a9f7
 public static void ContractListToDataList(List <CrudeFlightIdentifierContract> contractList, List <CrudeFlightIdentifierData> dataList)
 {
     foreach (CrudeFlightIdentifierContract contract in contractList)
     {
         var data = new CrudeFlightIdentifierData();
         CrudeFlightIdentifierService.ContractToData(contract, data);
         dataList.Add(data);
     }
 }
Exemplo n.º 2
0
        /// <summary>Get schedule record including identifiers and segments in displayable and updatable arrays</summary>
        /// <summary>Action log event inserted, exceptions logged</summary>
        /// <cardinality>One</cardinality>
        public FlightContract GetFlight(
            Guid flightId,
            Guid userId
            )
        {
            Logging.ActionLog("SolutionNorSolutionPort.BusinessLogicLayer.FlightService.GetFlight",
                              userId
                              );

            var flight =
                new FlightContract();

            try {
                // flight
                flight.Flight =
                    new CrudeFlightService().FetchByFlightId(flightId);

                // segments

                /*
                 * flight.FlightSegments =
                 *  new ScheduleSearchService().FlightSegments(flight).ToArray();
                 */

                flight.CrudeFlightSegments =
                    new CrudeFlightSegmentService().FetchByFlightId(flightId).ToArray();

                // flight identifier
                CrudeFlightIdentifierContract[] flightIdentifiers =
                    new CrudeFlightIdentifierService().FetchByFlightId(flightId).ToArray();

                // todo, can be more than one, use the one if existing, or make an empty one, should have room for more than one
                if (flightIdentifiers.Length > 0)
                {
                    flight.FlightIdentifier = flightIdentifiers[0];
                }
                else
                {
                    flight.FlightIdentifier = new CrudeFlightIdentifierContract();
                }
            } catch (Exception ex) {
                Logging.ErrorLog("Flight",
                                 "FlightService",
                                 "GetFlight",
                                 ex.Message,
                                 ex.StackTrace,
                                 userId
                                 );
                throw ex;
            }

            return(flight);
        }
Exemplo n.º 3
0
        public void UpdateFlight(
            FlightContract flightContract,
            Guid userId
            )
        {
            Logging.ActionLog("SolutionNorSolutionPort.BusinessLogicLayer.FlightService.UpdateFlight",
                              userId
                              );

            // start transaction
            using (var connection = new SqlConnection(Conn.ConnectionString)) {
                connection.Open();
                SqlTransaction transaction = connection.BeginTransaction();

                try {
                    // insert new flight
                    var crudeNewFlightData = new CrudeFlightData();
                    CrudeFlightService.ContractToData(
                        flightContract.Flight,
                        crudeNewFlightData
                        );

                    crudeNewFlightData.FlightId = Guid.NewGuid();

                    // binding flight id carries on forward
                    crudeNewFlightData.BindingFlightId = flightContract.Flight.BindingFlightId;

                    crudeNewFlightData.UserId   = userId;
                    crudeNewFlightData.DateTime = DateTime.UtcNow;
                    crudeNewFlightData.Insert(connection, transaction);

                    // todo, can be more than one
                    if (!String.IsNullOrEmpty(flightContract.FlightIdentifier.FlightIdentifierCode))
                    {
                        var crudeNewFlightIdentifierData = new CrudeFlightIdentifierData();

                        CrudeFlightIdentifierService.ContractToData(
                            flightContract.FlightIdentifier,
                            crudeNewFlightIdentifierData
                            );

                        crudeNewFlightIdentifierData.FlightIdentifierId      = Guid.NewGuid();
                        crudeNewFlightIdentifierData.FlightId                = crudeNewFlightData.FlightId;
                        crudeNewFlightIdentifierData.FlightIdentifierTypeRcd = FlightIdentifierTypeRef.FlightNumberThree;
                        crudeNewFlightIdentifierData.DateTime                = DateTime.UtcNow;
                        crudeNewFlightIdentifierData.UserId = userId;
                        crudeNewFlightIdentifierData.Insert(connection, transaction);
                    }

                    // update old flight schedule 'became' identifier
                    var crudeOldFlightData = new CrudeFlightData();
                    crudeOldFlightData.FetchByFlightId(flightContract.Flight.FlightId);
                    crudeOldFlightData.BecameFlightId = crudeNewFlightData.FlightId;
                    crudeOldFlightData.Update(connection, transaction);

                    // copy segments
                    List <CrudeFlightSegmentData> crudeFlightSegmentsData =
                        CrudeFlightSegmentData.FetchByFlightId(
                            flightContract.Flight.FlightId
                            );

                    foreach (CrudeFlightSegmentData crudeFlightSegmentData in crudeFlightSegmentsData)
                    {
                        crudeFlightSegmentData.FlightSegmentId = Guid.NewGuid();
                        crudeFlightSegmentData.FlightId        = crudeNewFlightData.FlightId;
                        crudeFlightSegmentData.DateTime        = DateTime.UtcNow;
                        crudeFlightSegmentData.UserId          = userId;
                        crudeFlightSegmentData.Insert(connection, transaction);
                    }

                    // commit transaction
                    transaction.Commit();
                } catch (Exception ex) {
                    transaction.Rollback();

                    Logging.ErrorLog("Flight",
                                     "FlightService",
                                     "UpdateFlight",
                                     ex.Message,
                                     ex.StackTrace,
                                     userId
                                     );
                    throw ex;
                }
            }
        }