// copy all rows from a List of serialized data objects in CrudeFlightScheduleIdentifierData to a List of SOAP Contracts // links: // docLink: http://sql2x.org/documentationLink/3d3e60c3-69e4-43d6-8bd5-14a67a6ecf58 public List <CrudeFlightScheduleIdentifierModel> FetchAll() { var list = new List <CrudeFlightScheduleIdentifierModel>(); List <CrudeFlightScheduleIdentifierData> dataList = CrudeFlightScheduleIdentifierData.FetchAll(); foreach (CrudeFlightScheduleIdentifierData crudeFlightScheduleIdentifierBusiness in dataList) { var model = new CrudeFlightScheduleIdentifierModel(); DataToModel(crudeFlightScheduleIdentifierBusiness, model); list.Add(model); } return(list); }
// 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 <CrudeFlightScheduleIdentifierModel> FetchWithFilter(System.Guid flightScheduleIdentifierId, System.Guid flightScheduleId, string flightIdentifierTypeRcd, string flightIdentifierCode, System.Guid userId, System.DateTime dateTime) { var list = new List <CrudeFlightScheduleIdentifierModel>(); List <CrudeFlightScheduleIdentifierData> dataList = CrudeFlightScheduleIdentifierData.FetchWithFilter(flightScheduleIdentifierId, flightScheduleId, flightIdentifierTypeRcd, flightIdentifierCode, userId, dateTime); foreach (CrudeFlightScheduleIdentifierData data in dataList) { var crudeFlightScheduleIdentifierBusinessModel = new CrudeFlightScheduleIdentifierModel(); DataToModel(data, crudeFlightScheduleIdentifierBusinessModel); list.Add(crudeFlightScheduleIdentifierBusinessModel); } return(list); }
// copy all rows from a List of serialized data objects in CrudeFlightScheduleIdentifierData to a List of SOAP Contracts // links: // docLink: http://sql2x.org/documentationLink/9204c68e-93b8-4c77-af3c-3181985ff75f public List <CrudeFlightScheduleIdentifierContract> FetchAll() { var list = new List <CrudeFlightScheduleIdentifierContract>(); List <CrudeFlightScheduleIdentifierData> dataList = CrudeFlightScheduleIdentifierData.FetchAll(); foreach (CrudeFlightScheduleIdentifierData crudeFlightScheduleIdentifier in dataList) { var contract = new CrudeFlightScheduleIdentifierContract(); DataToContract(crudeFlightScheduleIdentifier, contract); list.Add(contract); } return(list); }
// 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 <CrudeFlightScheduleIdentifierModel> FetchAllWithLimitAndOffset(string limit, string offset) { var list = new List <CrudeFlightScheduleIdentifierModel>(); List <CrudeFlightScheduleIdentifierData> dataList = CrudeFlightScheduleIdentifierData.FetchAllWithLimitAndOffset(int.Parse(limit), int.Parse(offset)); foreach (CrudeFlightScheduleIdentifierData crudeFlightScheduleIdentifierBusiness in dataList) { var model = new CrudeFlightScheduleIdentifierModel(); DataToModel(crudeFlightScheduleIdentifierBusiness, model); list.Add(model); } return(list); }
// 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 <CrudeFlightScheduleIdentifierContract> FetchAllWithLimitAndOffset(int limit, int offset) { var list = new List <CrudeFlightScheduleIdentifierContract>(); List <CrudeFlightScheduleIdentifierData> dataList = CrudeFlightScheduleIdentifierData.FetchAllWithLimitAndOffset(limit, offset); foreach (CrudeFlightScheduleIdentifierData crudeFlightScheduleIdentifier in dataList) { var contract = new CrudeFlightScheduleIdentifierContract(); DataToContract(crudeFlightScheduleIdentifier, contract); list.Add(contract); } return(list); }
// fetch by Primary key into new class instance // links: // crud definition: https://en.wikipedia.org/wiki/Create,_read,_update_and_delete // docLink: http://sql2x.org/documentationLink/7a625d0a-3028-42ce-a543-72ea3673cef4 // parameters: // flightScheduleIdentifierId: primary key of table flight_schedule_identifier public static CrudeFlightScheduleIdentifierData GetByFlightScheduleIdentifierId(System.Guid flightScheduleIdentifierId) { // create query against flight_schedule_identifier // this will be ansi sql and parameterized // parameterized queries are a good way of preventing sql injection // and to make sure the query plan is pre-compiled // links: // docLink: http://sql2x.org/documentationLink/72f5fc83-c460-40fe-bac9-73b7ee0c6b77 string sql = @" select top 1 flight_schedule_identifier_id, flight_schedule_id, flight_identifier_type_rcd, flight_identifier_code, user_id, date_time from [flight_schedule_identifier] where flight_schedule_identifier_id = @flight_schedule_identifier_id order by flight_identifier_code"; var ret = new CrudeFlightScheduleIdentifierData(); // open standard connection // the connection is found in web.config // the connection is closed upon completion of the reader // links: // docLink: http://sql2x.org/documentationLink/1ecca728-0c07-4dd7-b095-d10777b25b70 using (var conn = new SqlConnection(Conn.ConnectionString)) { conn.Open(); using (var command = new SqlCommand(sql, conn)) { // add primary key // this primary key will be used together with the prepared ansi sql statement // links: // docLink: http://sql2x.org/documentationLink/1ecca728-0c07-4dd7-b095-d10777b25b70 command.Parameters.Add("@flight_schedule_identifier_id", SqlDbType.UniqueIdentifier).Value = flightScheduleIdentifierId; // execute query against flight_schedule_identifier // if the query fails in the preprocessor of sql server // an exception will be raised // links: // docLink: http://sql2x.org/documentationLink/fd5c5faa-b400-4f29-b12b-9675c53a757f IDataReader reader = command.ExecuteReader(CommandBehavior.SingleRow); // populate serialized class if a row was found if (reader.Read()) { ret.Populate(reader); } } } return(ret); }
// fetch all rows from table flight_schedule_identifier into new List of class instances // links: // docLink: http://sql2x.org/documentationLink/7ca0c014-527e-4a0a-bd1f-12f4d8ea4b43 public static List <CrudeFlightScheduleIdentifierData> FetchAll() { var dataList = new List <CrudeFlightScheduleIdentifierData>(); // create query against flight_schedule_identifier // this will be ansi sql and parameterized // parameterized queries are a good way of preventing sql injection // and to make sure the query plan is pre-compiled // links: // docLink: http://sql2x.org/documentationLink/72f9f1bc-447c-4327-9d26-4b0790a07ff8 string sql = @" select flight_schedule_identifier_id, flight_schedule_id, flight_identifier_type_rcd, flight_identifier_code, user_id, date_time from [flight_schedule_identifier] order by flight_identifier_code"; // open standard connection // the connection is found in web.config // the connection is closed upon completion of the reader // links: // docLink: http://sql2x.org/documentationLink/952b3f82-bc00-4e82-9430-6bc26ff8bc4d using (var conn = new SqlConnection(Conn.ConnectionString)) { conn.Open(); using (var command = new SqlCommand(sql, conn)) { // execute query against flight_schedule_identifier // if the query fails in the preprocessor of sql server // an exception will be raised // links: // docLink: http://sql2x.org/documentationLink/ed55cc5b-d6be-4f5e-9385-ee726dfc2bf1 IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult); // read all rows returned from the query of flight_schedule_identifier // read all columns from the datareader and // populate the List of C# objects with them // links: // docLink: http://sql2x.org/documentationLink/c1b8b800-b250-4822-a699-d93a35f4414d while (reader.Read()) { var data = new CrudeFlightScheduleIdentifierData(); data.Populate(reader); dataList.Add(data); } } return(dataList); } }
// fetch all from table into new List of class instances, with a limit on number of returned rows and order by columns // links: // docLink: http://sql2x.org/documentationLink/dfaa482b-059b-4f17-a9a9-4885138dbb46 public static List <CrudeFlightScheduleIdentifierData> FetchAllWithLimit(int limit) { var dataList = new List <CrudeFlightScheduleIdentifierData>(); // create query against flight_schedule_identifier // this will be ansi sql and parameterized // parameterized queries are a good way of preventing sql injection // and to make sure the query plan is pre-compiled // links: // docLink: http://sql2x.org/documentationLink/41f82773-6d37-4ebe-840c-c60e06337f45 string sql = @" select top " + limit.ToString() + @" flight_schedule_identifier_id, flight_schedule_id, flight_identifier_type_rcd, flight_identifier_code, user_id, date_time from [flight_schedule_identifier] order by flight_identifier_code"; // open standard connection // the connection is found in web.config // the connection is closed upon completion of the reader // links: // docLink: http://sql2x.org/documentationLink/da228d98-b30e-4d79-89ae-98e813437753 using (var conn = new SqlConnection(Conn.ConnectionString)) { conn.Open(); using (var command = new SqlCommand(sql, conn)) { // execute query against flight_schedule_identifier // if the query fails in the preprocessor of sql server // an exception will be raised // links: // docLink: http://sql2x.org/documentationLink/c32ad724-8a03-4b4c-b6fb-a5abfb1d707e IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult); // read all rows returned from the query of flight_schedule_identifier // read all columns from the datareader and // populate the List of C# objects with them // links: // docLink: http://sql2x.org/documentationLink/9ba4395d-d8a4-4427-b80f-7b828e34da7a while (reader.Read()) { var data = new CrudeFlightScheduleIdentifierData(); data.Populate(reader); dataList.Add(data); } } return(dataList); } }
// 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 <CrudeFlightScheduleIdentifierContract> FetchWithFilter(System.Guid flightScheduleIdentifierId, System.Guid flightScheduleId, string flightIdentifierTypeRcd, string flightIdentifierCode, System.Guid userId, System.DateTime dateTime) { var list = new List <CrudeFlightScheduleIdentifierContract>(); List <CrudeFlightScheduleIdentifierData> dataList = CrudeFlightScheduleIdentifierData.FetchWithFilter( flightScheduleIdentifierId: flightScheduleIdentifierId, flightScheduleId: flightScheduleId, flightIdentifierTypeRcd: flightIdentifierTypeRcd, flightIdentifierCode: flightIdentifierCode, userId: userId, dateTime: dateTime ); foreach (CrudeFlightScheduleIdentifierData data in dataList) { var crudeFlightScheduleIdentifierContract = new CrudeFlightScheduleIdentifierContract(); DataToContract(data, crudeFlightScheduleIdentifierContract); list.Add(crudeFlightScheduleIdentifierContract); } return(list); }
// 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(CrudeFlightScheduleIdentifierContract contract, CrudeFlightScheduleIdentifierData data) { data.FlightScheduleIdentifierId = contract.FlightScheduleIdentifierId; data.FlightScheduleId = contract.FlightScheduleId; data.FlightIdentifierTypeRcd = contract.FlightIdentifierTypeRcd; data.FlightIdentifierCode = contract.FlightIdentifierCode; data.UserId = contract.UserId; data.DateTime = contract.DateTime; }
// 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 flightScheduleIdentifierId) { CrudeFlightScheduleIdentifierData.Delete(flightScheduleIdentifierId); }
// get a count of rows in table // links: // docLink: http://sql2x.org/documentationLink/7cd5e52c-b3d7-4566-a27a-408d0732dd88 public int FetchAllCount() { return(CrudeFlightScheduleIdentifierData.FetchAllCount()); }
// fetch by Foreign key into new List of class instances // links: // docLink: http://sql2x.org/documentationLink/a7599485-4f00-4ebf-974d-53f69c43654e public List <CrudeFlightScheduleIdentifierContract> FetchByFlightIdentifierTypeRcd(string flightIdentifierTypeRcd) { return(DataListToContractList(CrudeFlightScheduleIdentifierData.FetchByFlightIdentifierTypeRcd(flightIdentifierTypeRcd))); }
// fetch by Foreign key into new List of class instances // links: // docLink: http://sql2x.org/documentationLink/a7599485-4f00-4ebf-974d-53f69c43654e public List <CrudeFlightScheduleIdentifierContract> FetchByUserId(System.Guid userId) { return(DataListToContractList(CrudeFlightScheduleIdentifierData.FetchByUserId(userId))); }
// fetch by Search key into current object // links: // crud definition: https://en.wikipedia.org/wiki/Create,_read,_update_and_delete // docLink: http://sql2x.org/documentationLink/87368fa6-b618-4f0c-acbb-1fc4e273bb2d // parameters: // UserId: key of table CrudeFlightScheduleIdentifierData public List <CrudeFlightScheduleIdentifierModel> FetchByUserId(System.Guid userId) { return(DataListToModelList(CrudeFlightScheduleIdentifierData.FetchByUserId(userId))); }
// fetch by Search key into current object // links: // crud definition: https://en.wikipedia.org/wiki/Create,_read,_update_and_delete // docLink: http://sql2x.org/documentationLink/87368fa6-b618-4f0c-acbb-1fc4e273bb2d // parameters: // FlightIdentifierTypeRcd: key of table CrudeFlightScheduleIdentifierData public List <CrudeFlightScheduleIdentifierModel> FetchByFlightIdentifierTypeRcd(string flightIdentifierTypeRcd) { return(DataListToModelList(CrudeFlightScheduleIdentifierData.FetchByFlightIdentifierTypeRcd(flightIdentifierTypeRcd))); }
// fetch all from table into new List of class instances, filtered by any column // links: // docLink: http://sql2x.org/documentationLink/a736bbfd-030d-492e-a86a-7a5e478eeb79 public static List <CrudeFlightScheduleIdentifierData> FetchWithFilter(System.Guid flightScheduleIdentifierId, System.Guid flightScheduleId, string flightIdentifierTypeRcd, string flightIdentifierCode, System.Guid userId, System.DateTime dateTime) { var dataList = new List <CrudeFlightScheduleIdentifierData>(); // create query against flight_schedule_identifier // this will be ansi sql and parameterized // parameterized queries are a good way of preventing sql injection // and to make sure the query plan is pre-compiled // links: // docLink: http://sql2x.org/documentationLink/06da7a50-8760-48cd-b789-a41cac3edd13 string sql = @" select flight_schedule_identifier_id, flight_schedule_id, flight_identifier_type_rcd, flight_identifier_code, user_id, date_time from [flight_schedule_identifier] where 1 = 1"; // open standard connection // the connection is found in web.config // the connection is closed upon completion of the reader // links: // docLink: http://sql2x.org/documentationLink/6ec2495f-3a49-4a94-ad59-0ce064fc8654 using (var conn = new SqlConnection(Conn.ConnectionString)) { conn.Open(); using (var command = new SqlCommand(sql, conn)) { // add search column(s) if they are not null or empty // this search column(s) will be used together with the prepared ansi sql statement // links: // docLink: http://sql2x.org/documentationLink/2193123a-3534-412b-8521-dac14bb3884d if (flightScheduleIdentifierId != Guid.Empty) { sql += " and flight_schedule_identifier_id = @flight_schedule_identifier_id"; command.Parameters.Add("@flight_schedule_identifier_id", SqlDbType.UniqueIdentifier).Value = flightScheduleIdentifierId; } if (flightScheduleId != Guid.Empty) { sql += " and flight_schedule_id = @flight_schedule_id"; command.Parameters.Add("@flight_schedule_id", SqlDbType.UniqueIdentifier).Value = flightScheduleId; } if (!string.IsNullOrEmpty(flightIdentifierTypeRcd)) { sql += " and flight_identifier_type_rcd like '%' + @flight_identifier_type_rcd + '%'"; command.Parameters.Add("@flight_identifier_type_rcd", SqlDbType.NVarChar).Value = flightIdentifierTypeRcd.Replace("'", "''"); } if (!string.IsNullOrEmpty(flightIdentifierCode)) { sql += " and flight_identifier_code like '%' + @flight_identifier_code + '%'"; command.Parameters.Add("@flight_identifier_code", SqlDbType.NVarChar).Value = flightIdentifierCode.Replace("'", "''"); } if (userId != Guid.Empty) { sql += " and user_id = @user_id"; command.Parameters.Add("@user_id", SqlDbType.UniqueIdentifier).Value = userId; } if (dateTime != DateTime.MinValue) { sql += " and date_time = @date_time"; command.Parameters.Add("@date_time", SqlDbType.DateTime).Value = dateTime; } sql += " order by flight_identifier_code"; command.CommandText = sql; // execute query against flight_schedule_identifier // if the query fails in the preprocessor of sql server // an exception will be raised // links: // docLink: http://sql2x.org/documentationLink/9f9fcbf4-4764-4b2e-8dc6-41d0366c95c9 IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult); // read all rows returned from the query of flight_schedule_identifier // read all columns from the datareader and // populate the List of C# objects with them // links: // docLink: http://sql2x.org/documentationLink/60181c7c-4a5e-41a3-9599-4e7a0aaf0cc8 while (reader.Read()) { var data = new CrudeFlightScheduleIdentifierData(); data.Populate(reader); dataList.Add(data); } } return(dataList); } }
/// <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; } } }