Exemple #1
0
        // update all object members on a row in table based on primary key
        // links:
        //  docLink: http://sql2x.org/documentationLink/ce75e72e-fb16-4f4e-a2e6-dbd079dfa206
        public void Update(CrudeFlightContract contract)
        {
            var data = new CrudeFlightData();

            ContractToData(contract, data);
            data.Update();
        }
Exemple #2
0
        // insert all object members as a new row in table
        // links:
        //  docLink: http://sql2x.org/documentationLink/75aad010-e6aa-4f19-a6e5-597456aa20d8
        public void Insert(CrudeFlightContract contract)
        {
            var data = new CrudeFlightData();

            ContractToData(contract, data);
            data.Insert();
        }
Exemple #3
0
        // fetch all rows from table into new List of Contracts, filtered by any column
        // links:
        //  docLink: http://sql2x.org/documentationLink/ce01ef4a-5cd0-4e51-b211-9c0a15b791a0
        public List <CrudeFlightContract> FetchWithFilter(System.Guid flightId, System.Guid becameFlightId, System.Guid bindingFlightId, System.Guid airlineId, System.Guid aircraftId, string aircraftTypeRcd, System.Guid departureAirportId, System.Guid arrivalAirportId, System.DateTime fromDateTime, System.DateTime untilDateTime, string comment, System.Guid userId, System.DateTime dateTime)
        {
            var list = new List <CrudeFlightContract>();
            List <CrudeFlightData> dataList = CrudeFlightData.FetchWithFilter(
                flightId: flightId,
                becameFlightId: becameFlightId,
                bindingFlightId: bindingFlightId,
                airlineId: airlineId,
                aircraftId: aircraftId,
                aircraftTypeRcd: aircraftTypeRcd,
                departureAirportId: departureAirportId,
                arrivalAirportId: arrivalAirportId,
                fromDateTime: fromDateTime,
                untilDateTime: untilDateTime,
                comment: comment,
                userId: userId,
                dateTime: dateTime
                );

            foreach (CrudeFlightData data in dataList)
            {
                var crudeFlightContract = new CrudeFlightContract();
                DataToContract(data, crudeFlightContract);
                list.Add(crudeFlightContract);
            }

            return(list);
        }
Exemple #4
0
        // update all object members on a row in table based on primary key, on a transaction
        // the transaction and or connection state is not changed in any way other than what SqlClient does to it.
        // it is the callers responsibility to commit or rollback the transaction
        // links:
        //  docLink: http://sql2x.org/documentationLink/b798ad6b-f4b8-466a-9086-6588a814fcf3
        public void Update(CrudeFlightContract contract, SqlConnection connection, SqlTransaction transaction)
        {
            var data = new CrudeFlightData();

            ContractToData(contract, data);
            data.Update(connection, transaction);
        }
        // transfer model to data and update, on a transaction
        // links:
        //  docLink: http://sql2x.org/documentationLink/aa07e05b-edc8-4e09-bf93-bf2a40c93c09
        public void Update(CrudeFlightModel model, SqlConnection connection, SqlTransaction transaction)
        {
            var data = new CrudeFlightData();

            ModelToData(model, data);
            data.Update(connection, transaction);
        }
        // transfer model to data and insert
        // links:
        //  docLink: http://sql2x.org/documentationLink/17cd8423-3c78-459f-a45b-773fcfbc3b7d
        public void Insert(CrudeFlightModel model)
        {
            var data = new CrudeFlightData();

            ModelToData(model, data);
            data.Insert();
        }
        // transfer model to data and update
        // links:
        //  docLink: http://sql2x.org/documentationLink/658fda50-2ad3-414e-9299-2b399d17a057
        public void Update(CrudeFlightModel model)
        {
            var data = new CrudeFlightData();

            ModelToData(model, data);
            data.Update();
        }
Exemple #8
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 <CrudeFlightContract> contractList, List <CrudeFlightData> dataList)
 {
     foreach (CrudeFlightContract contract in contractList)
     {
         var data = new CrudeFlightData();
         CrudeFlightService.ContractToData(contract, data);
         dataList.Add(data);
     }
 }
 // transfer model list to data list
 // links:
 //  crud definition: https://en.wikipedia.org/wiki/Create,_read,_update_and_delete
 //  docLink: http://sql2x.org/documentationLink/1d6a48d9-fe39-4397-b8fa-a332da164cbf
 // parameters:
 //  CrudeFlightData: key of table CrudeFlightData
 public static void ModelListToDataList(List <CrudeFlightModel> modelList, List <CrudeFlightData> dataList)
 {
     foreach (CrudeFlightModel model in modelList)
     {
         var data = new CrudeFlightData();
         ModelToData(model, data);
         dataList.Add(data);
     }
 }
Exemple #10
0
        // fetch by Primary key into current object
        // links:
        //  crud definition: https://en.wikipedia.org/wiki/Create,_read,_update_and_delete
        //  docLink: http://sql2x.org/documentationLink/bbab4791-c9e7-49bf-90d5-fca19b1fedaa
        // parameters:
        //  flightId: primary key of table flight
        public CrudeFlightContract FetchByFlightId(System.Guid flightId)
        {
            var dataAccessLayer = new CrudeFlightData();
            var contract        = new CrudeFlightContract();

            dataAccessLayer.FetchByFlightId(flightId);
            DataToContract(dataAccessLayer, contract);

            return(contract);
        }
Exemple #11
0
        // fetch by Primary key into current object
        // links:
        //  crud definition: https://en.wikipedia.org/wiki/Create,_read,_update_and_delete
        //  docLink: http://sql2x.org/documentationLink/fdcc33b4-08f1-43c3-ae28-95fbf029c3bd
        // parameters:
        //  CrudeFlightData: primary key of table CrudeFlightData
        public CrudeFlightModel FetchByFlightId(System.Guid flightId)
        {
            var dataAccessLayer = new CrudeFlightData();
            var model           = new CrudeFlightModel();

            dataAccessLayer.FetchByFlightId(flightId);
            DataToModel(dataAccessLayer, model);

            return(model);
        }
Exemple #12
0
        // copy all rows from a List of serialized data objects to a List of SOAP Contracts,
        //  with a limit on number of returned rows and order by columns, starting at a specific row
        // links:
        //  docLink: http://sql2x.org/documentationLink/3fe9f1b3-97b6-4f58-a0f2-adfcbd973bfc
        public List <CrudeFlightContract> FetchAllWithLimitAndOffset(int limit, int offset)
        {
            var list = new List <CrudeFlightContract>();
            List <CrudeFlightData> dataList = CrudeFlightData.FetchAllWithLimitAndOffset(limit, offset);

            foreach (CrudeFlightData crudeFlight in dataList)
            {
                var contract = new CrudeFlightContract();
                DataToContract(crudeFlight, contract);
                list.Add(contract);
            }

            return(list);
        }
Exemple #13
0
        // fetch all from table into new List of class instances, filtered by any column
        // links:
        //  docLink: http://sql2x.org/documentationLink/db27658d-4d23-46d7-9970-7bbaef8634b0
        public List <CrudeFlightModel> FetchWithFilter(System.Guid flightId, System.Guid becameFlightId, System.Guid bindingFlightId, System.Guid airlineId, System.Guid aircraftId, string aircraftTypeRcd, System.Guid departureAirportId, System.Guid arrivalAirportId, System.DateTime fromDateTime, System.DateTime untilDateTime, string comment, System.Guid userId, System.DateTime dateTime)
        {
            var list = new List <CrudeFlightModel>();
            List <CrudeFlightData> dataList = CrudeFlightData.FetchWithFilter(flightId, becameFlightId, bindingFlightId, airlineId, aircraftId, aircraftTypeRcd, departureAirportId, arrivalAirportId, fromDateTime, untilDateTime, comment, userId, dateTime);

            foreach (CrudeFlightData data in dataList)
            {
                var crudeFlightBusinessModel = new CrudeFlightModel();
                DataToModel(data, crudeFlightBusinessModel);
                list.Add(crudeFlightBusinessModel);
            }

            return(list);
        }
Exemple #14
0
        // fetch all rows from table with an offset, and limit of rows
        // links:
        //  docLink: http://sql2x.org/documentationLink/a87e5c54-b47e-4031-bc3b-837b4cf9f692
        public List <CrudeFlightModel> FetchAllWithLimitAndOffset(string limit, string offset)
        {
            var list = new List <CrudeFlightModel>();
            List <CrudeFlightData> dataList = CrudeFlightData.FetchAllWithLimitAndOffset(int.Parse(limit), int.Parse(offset));

            foreach (CrudeFlightData crudeFlightBusiness in dataList)
            {
                var model = new CrudeFlightModel();
                DataToModel(crudeFlightBusiness, model);
                list.Add(model);
            }

            return(list);
        }
Exemple #15
0
        // copy all rows from a List of serialized data objects in CrudeFlightData to a List of SOAP Contracts
        // links:
        //  docLink: http://sql2x.org/documentationLink/3d3e60c3-69e4-43d6-8bd5-14a67a6ecf58
        public List <CrudeFlightModel> FetchAll()
        {
            var list = new List <CrudeFlightModel>();
            List <CrudeFlightData> dataList = CrudeFlightData.FetchAll();

            foreach (CrudeFlightData crudeFlightBusiness in dataList)
            {
                var model = new CrudeFlightModel();
                DataToModel(crudeFlightBusiness, model);
                list.Add(model);
            }

            return(list);
        }
Exemple #16
0
        // copy all rows from a List of serialized data objects in CrudeFlightData to a List of SOAP Contracts
        // links:
        //  docLink: http://sql2x.org/documentationLink/9204c68e-93b8-4c77-af3c-3181985ff75f
        public List <CrudeFlightContract> FetchAll()
        {
            var list = new List <CrudeFlightContract>();
            List <CrudeFlightData> dataList = CrudeFlightData.FetchAll();

            foreach (CrudeFlightData crudeFlight in dataList)
            {
                var contract = new CrudeFlightContract();
                DataToContract(crudeFlight, contract);
                list.Add(contract);
            }

            return(list);
        }
Exemple #17
0
 // copy all columns from a SOAP Contract to a serialized data object
 // links:
 //  docLink: http://sql2x.org/documentationLink/10700d38-2227-4021-be12-2f4f206f5dd9
 public static void ContractToData(CrudeFlightContract contract, CrudeFlightData data)
 {
     data.FlightId           = contract.FlightId;
     data.BecameFlightId     = contract.BecameFlightId;
     data.BindingFlightId    = contract.BindingFlightId;
     data.AirlineId          = contract.AirlineId;
     data.AircraftId         = contract.AircraftId;
     data.AircraftTypeRcd    = contract.AircraftTypeRcd;
     data.DepartureAirportId = contract.DepartureAirportId;
     data.ArrivalAirportId   = contract.ArrivalAirportId;
     data.FromDateTime       = contract.FromDateTime;
     data.UntilDateTime      = contract.UntilDateTime;
     data.Comment            = contract.Comment;
     data.UserId             = contract.UserId;
     data.DateTime           = contract.DateTime;
 }
Exemple #18
0
 // transfer data object to model object
 // links:
 //  docLink: http://sql2x.org/documentationLink/43d57600-5ff5-4ef8-9330-123773d100d3
 public static void DataToModel(CrudeFlightData data, CrudeFlightModel model)
 {
     model.FlightId           = data.FlightId;
     model.BecameFlightId     = data.BecameFlightId;
     model.BindingFlightId    = data.BindingFlightId;
     model.AirlineId          = data.AirlineId;
     model.AircraftId         = data.AircraftId;
     model.AircraftTypeRcd    = data.AircraftTypeRcd;
     model.DepartureAirportId = data.DepartureAirportId;
     model.ArrivalAirportId   = data.ArrivalAirportId;
     model.FromDateTime       = data.FromDateTime;
     model.UntilDateTime      = data.UntilDateTime;
     model.Comment            = data.Comment;
     model.UserId             = data.UserId;
     model.DateTime           = data.DateTime;
 }
Exemple #19
0
 // transfer model object to data object
 // links:
 //  docLink: http://sql2x.org/documentationLink/95875d99-b7f7-4a9e-baa4-3fbe9925d8a2
 public static void ModelToData(CrudeFlightModel model, CrudeFlightData data)
 {
     data.FlightId           = model.FlightId;
     data.BecameFlightId     = model.BecameFlightId;
     data.BindingFlightId    = model.BindingFlightId;
     data.AirlineId          = model.AirlineId;
     data.AircraftId         = model.AircraftId;
     data.AircraftTypeRcd    = model.AircraftTypeRcd;
     data.DepartureAirportId = model.DepartureAirportId;
     data.ArrivalAirportId   = model.ArrivalAirportId;
     data.FromDateTime       = model.FromDateTime;
     data.UntilDateTime      = model.UntilDateTime;
     data.Comment            = model.Comment;
     data.UserId             = model.UserId;
     data.DateTime           = model.DateTime;
 }
Exemple #20
0
 // copy all columns from a serialized data object to a SOAP Contract
 // links:
 //  docLink: http://sql2x.org/documentationLink/7553d6dd-da65-4a72-84c8-81f2f99ef4f5
 public static void DataToContract(CrudeFlightData data, CrudeFlightContract contract)
 {
     contract.FlightId           = data.FlightId;
     contract.BecameFlightId     = data.BecameFlightId;
     contract.BindingFlightId    = data.BindingFlightId;
     contract.AirlineId          = data.AirlineId;
     contract.AircraftId         = data.AircraftId;
     contract.AircraftTypeRcd    = data.AircraftTypeRcd;
     contract.DepartureAirportId = data.DepartureAirportId;
     contract.ArrivalAirportId   = data.ArrivalAirportId;
     contract.FromDateTime       = data.FromDateTime;
     contract.UntilDateTime      = data.UntilDateTime;
     contract.Comment            = data.Comment;
     contract.UserId             = data.UserId;
     contract.DateTime           = data.DateTime;
 }
Exemple #21
0
        /// <summary>get closest flight matching departure and arrival</summary>
        public static Guid GetFlightMatching(
            Guid departureAirportId,
            Guid arrivalArportId
            )
        {
            var ret = new CrudeFlightData();

            string sql = @" 
                select top 1
                    flight_id
                from flight	as fl
                where fl.departure_airport_id = @departure_airport_id
                  and fl.arrival_airport_id = @arrival_airport_id
				  and fl.from_date_time > getutcdate()
				order by fl.from_date_time 
                ";

            Guid flight = Guid.Empty;

            using (var conn = new SqlConnection(Conn.ConnectionString)) {
                conn.Open();

                using (var command = new SqlCommand(sql, conn)) {
                    command.Parameters.Add("@departure_airport_id", SqlDbType.UniqueIdentifier).Value = departureAirportId;
                    command.Parameters.Add("@arrival_airport_id", SqlDbType.UniqueIdentifier).Value   = arrivalArportId;

                    Logging     log    = Logging.PerformanceTimeStart("SolutionNorSolutionPort.DataAccessLayer.Flight.GetFlightMatching");
                    IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);
                    log.PerformanceTimeStop(sql, command);

                    if (reader.Read())
                    {
                        flight = ( Guid )reader["flight_id"];
                    }
                }

                return(flight);
            }
        }
Exemple #22
0
 // delete a row in table based on primary key
 // links:
 //  docLink: http://sql2x.org/documentationLink/eb0597e0-8ea0-425c-88af-213a170bbd5e
 public void Delete(System.Guid flightId)
 {
     CrudeFlightData.Delete(flightId);
 }
Exemple #23
0
 // fetch by Foreign key into new List of class instances
 // links:
 //  docLink: http://sql2x.org/documentationLink/a7599485-4f00-4ebf-974d-53f69c43654e
 public List <CrudeFlightContract> FetchByDepartureAirportId(System.Guid departureAirportId)
 {
     return(DataListToContractList(CrudeFlightData.FetchByDepartureAirportId(departureAirportId)));
 }
Exemple #24
0
 // fetch by Foreign key into new List of class instances
 // links:
 //  docLink: http://sql2x.org/documentationLink/a7599485-4f00-4ebf-974d-53f69c43654e
 public List <CrudeFlightContract> FetchByBindingFlightId(System.Guid bindingFlightId)
 {
     return(DataListToContractList(CrudeFlightData.FetchByBindingFlightId(bindingFlightId)));
 }
Exemple #25
0
 // fetch by Foreign key into new List of class instances
 // links:
 //  docLink: http://sql2x.org/documentationLink/a7599485-4f00-4ebf-974d-53f69c43654e
 public List <CrudeFlightContract> FetchByAircraftId(System.Guid aircraftId)
 {
     return(DataListToContractList(CrudeFlightData.FetchByAircraftId(aircraftId)));
 }
Exemple #26
0
 // fetch by Foreign key into new List of class instances
 // links:
 //  docLink: http://sql2x.org/documentationLink/a7599485-4f00-4ebf-974d-53f69c43654e
 public List <CrudeFlightContract> FetchByUserId(System.Guid userId)
 {
     return(DataListToContractList(CrudeFlightData.FetchByUserId(userId)));
 }
Exemple #27
0
 // fetch by Foreign key into new List of class instances
 // links:
 //  docLink: http://sql2x.org/documentationLink/a7599485-4f00-4ebf-974d-53f69c43654e
 public List <CrudeFlightContract> FetchByAircraftTypeRcd(string aircraftTypeRcd)
 {
     return(DataListToContractList(CrudeFlightData.FetchByAircraftTypeRcd(aircraftTypeRcd)));
 }
Exemple #28
0
 // get a count of rows in table
 // links:
 //  docLink: http://sql2x.org/documentationLink/7cd5e52c-b3d7-4566-a27a-408d0732dd88
 public int FetchAllCount()
 {
     return(CrudeFlightData.FetchAllCount());
 }
Exemple #29
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;
                }
            }
        }
Exemple #30
0
 // fetch by Foreign key into new List of class instances
 // links:
 //  docLink: http://sql2x.org/documentationLink/a7599485-4f00-4ebf-974d-53f69c43654e
 public List <CrudeFlightContract> FetchByArrivalAirportId(System.Guid arrivalAirportId)
 {
     return(DataListToContractList(CrudeFlightData.FetchByArrivalAirportId(arrivalAirportId)));
 }