예제 #1
0
        /// <summary>Create schedule record including identifiers</summary>
        /// <summary>Action log event inserted, exceptions logged</summary>
        public void CreateSchedule(
            ScheduleContract scheduleContract,
            Guid userId
            )
        {
            Logging.ActionLog("SolutionNorSolutionPort.BusinessLogicLayer.ScheduleService.CreateSchedule",
                              userId
                              );

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

                try {
                    // insert flight schedule
                    var crudeFlightScheduleData = new CrudeFlightScheduleData();
                    CrudeFlightScheduleService.ContractToData(
                        scheduleContract.FlightSchedule,
                        crudeFlightScheduleData
                        );

                    crudeFlightScheduleData.FlightScheduleId = Guid.NewGuid();

                    // first flight schedule id has equal flight schedule id
                    crudeFlightScheduleData.BindingFlightScheduleId = crudeFlightScheduleData.FlightScheduleId;

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

                    // insert flight identifier, if existing
                    // todo, there can be more than one identifier
                    if (!String.IsNullOrEmpty(scheduleContract.FlightScheduleIdentifier.FlightIdentifierCode))
                    {
                        var crudeFlightScheduleIdentifierData = new CrudeFlightScheduleIdentifierData();
                        crudeFlightScheduleIdentifierData.FlightScheduleId        = crudeFlightScheduleData.FlightScheduleId;
                        crudeFlightScheduleIdentifierData.FlightIdentifierCode    = scheduleContract.FlightScheduleIdentifier.FlightIdentifierCode;
                        crudeFlightScheduleIdentifierData.FlightIdentifierTypeRcd = FlightIdentifierTypeRef.FlightNumberThree;
                        crudeFlightScheduleIdentifierData.DateTime = DateTime.UtcNow;
                        crudeFlightScheduleIdentifierData.UserId   = userId;
                        crudeFlightScheduleIdentifierData.Insert(connection, transaction);
                    }

                    // commit transaction
                    transaction.Commit();
                } catch (Exception ex) {
                    transaction.Rollback();
                    Logging.ErrorLog("Schedule",
                                     "ScheduleService",
                                     "CreateSchedule",
                                     ex.Message,
                                     ex.StackTrace,
                                     userId
                                     );
                    throw ex;
                }
            }
        }
예제 #2
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 <CrudeFlightScheduleContract> contractList, List <CrudeFlightScheduleData> dataList)
 {
     foreach (CrudeFlightScheduleContract contract in contractList)
     {
         var data = new CrudeFlightScheduleData();
         CrudeFlightScheduleService.ContractToData(contract, data);
         dataList.Add(data);
     }
 }
예제 #3
0
        public void MakeFlightsFromScheduleAll(
            Guid userId
            )
        {
            var scheduleList = new CrudeFlightScheduleService().FetchAll();

            foreach (var scheduleItem in scheduleList)
            {
                if (scheduleItem.BecameFlightScheduleId == Guid.Empty)
                {
                    MakeFlightsFromSchedule(
                        scheduleItem.FlightScheduleId,
                        userId
                        );
                }
            }
        }
예제 #4
0
        /// <summary>Update schedule record including identifiers</summary>
        /// <summary>Identifier will be created if not existing</summary>
        /// <summary>Action log event inserted, exceptions logged</summary>
        public void UpdateSchedule(
            ScheduleContract scheduleContract,
            Guid userId
            )
        {
            Logging.ActionLog("SolutionNorSolutionPort.BusinessLogicLayer.ScheduleService.UpdateSchedule",
                              userId
                              );

            // make sure this is not an historical record
            if (scheduleContract.FlightSchedule.BecameFlightScheduleId != Guid.Empty)
            {
                Logging.ErrorLog("Schedule",
                                 "ScheduleService",
                                 "UpdateSchedule",
                                 "Schedule.UpdateSchedule: Can not update a history schedule flight record",
                                 string.Empty,
                                 userId
                                 );

                throw new Exception("Schedule.UpdateSchedule: Can not update a history schedule flight record");
            }

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

                try {
                    // insert new flight schedule
                    var crudeNewFlightScheduleData = new CrudeFlightScheduleData();
                    CrudeFlightScheduleService.ContractToData(
                        scheduleContract.FlightSchedule,
                        crudeNewFlightScheduleData
                        );

                    crudeNewFlightScheduleData.FlightScheduleId = Guid.NewGuid();

                    // binding flight schedule id carries on forward
                    crudeNewFlightScheduleData.BindingFlightScheduleId = scheduleContract.FlightSchedule.BindingFlightScheduleId;

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

                    // insert new identifier
                    // todo, can be more than one
                    if (scheduleContract.FlightScheduleIdentifier.FlightIdentifierCode != string.Empty)
                    {
                        var crudeNewFlightScheduleIdentifierData = new CrudeFlightScheduleIdentifierData();

                        CrudeFlightScheduleIdentifierService.ContractToData(
                            scheduleContract.FlightScheduleIdentifier,
                            crudeNewFlightScheduleIdentifierData
                            );

                        crudeNewFlightScheduleIdentifierData.FlightScheduleIdentifierId = Guid.NewGuid();
                        crudeNewFlightScheduleIdentifierData.FlightScheduleId           = crudeNewFlightScheduleData.FlightScheduleId;
                        crudeNewFlightScheduleIdentifierData.FlightIdentifierTypeRcd    = FlightIdentifierTypeRef.FlightNumberThree;
                        crudeNewFlightScheduleIdentifierData.DateTime = DateTime.UtcNow;
                        crudeNewFlightScheduleIdentifierData.UserId   = userId;
                        crudeNewFlightScheduleIdentifierData.Insert(connection, transaction);
                    }

                    // update old flight schedule 'became' identifier
                    var crudeOldFlightScheduleData = new CrudeFlightScheduleData();
                    crudeOldFlightScheduleData.FetchByFlightScheduleId(scheduleContract.FlightSchedule.FlightScheduleId);
                    crudeOldFlightScheduleData.BecameFlightScheduleId = crudeNewFlightScheduleData.FlightScheduleId;
                    crudeOldFlightScheduleData.Update(connection, transaction);

                    // copy schedule segments
                    List <CrudeFlightScheduleSegmentData> crudeFlightScheduleSegmentsData =
                        CrudeFlightScheduleSegmentData.FetchByFlightScheduleId(
                            scheduleContract.FlightSchedule.FlightScheduleId
                            );

                    foreach (CrudeFlightScheduleSegmentData crudeFlightScheduleSegmentData in crudeFlightScheduleSegmentsData)
                    {
                        crudeFlightScheduleSegmentData.FlightScheduleSegmentId = Guid.NewGuid();
                        crudeFlightScheduleSegmentData.FlightScheduleId        = crudeNewFlightScheduleData.FlightScheduleId;
                        crudeFlightScheduleSegmentData.DateTime = DateTime.UtcNow;
                        crudeFlightScheduleSegmentData.UserId   = userId;
                        crudeFlightScheduleSegmentData.Insert(connection, transaction);
                    }

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

                    Logging.ErrorLog("Schedule",
                                     "ScheduleService",
                                     "UpdateSchedule",
                                     ex.Message,
                                     ex.StackTrace,
                                     userId
                                     );
                    throw ex;
                }
            }
        }