C# Sample insert profile

43 views
Skip to first unread message

Dan Palley

unread,
Nov 11, 2019, 1:59:42 PM11/11/19
to TramsAPI Beta
 I'm continuing to refine the object classes in the C# sample code.  Here's an example of inserting a simple leisure profile:

        Profile profile = new Profile(session);

        await profile.Prepare();
        
        profile.ProfileRow[Profile.Field_Profile_ProfileType_LinkCode] = Profile.Literal_ProfileType_Leisure;
        profile.ProfileRow[Profile.Field_Profile_Name] = "Palley/Dan";
        profile.AddRow(profile.ProfileRow);

        profile.PassengerRow[Profile.Field_Passenger_FirstName] = "Dan";
        profile.PassengerRow[Profile.Field_Passenger_LastName] = "Palley";
        profile.PassengerRow[Profile.Field_ProfilePassenger_IsPrimary] = "Y";
        profile.PassengerRow = profile.AddRow(profile.PassengerRow);

profile.PassengerRow[Profile.Field_Passenger_FirstName] = "Tyson";
        profile.PassengerRow[Profile.Field_Passenger_LastName] = "Palley";
        profile.AddRow(profile.PassengerRow);        

await profile.Save();

  • profile.Prepare() initializes the underlying dataset, fetching the metadata from the server, including creating the default DataRow instances (ProfileRow, PassengerRow).
  • ProfileRow and PassengerRow are pre-defined in the Profile class.  
  • AddRow() adds the specified row to the corresponding data table and automatically links the row to the parent table/row, if applicable. AddRow() returns a new blank row that can be used for inserting additional rows of the same type.
Here's the revised Insert Invoice sample:

        Invoice invoice = new Invoice(session);

        await invoice.Prepare();

        invoice.InvoiceRow[Invoice.Field_Invoice_InvoiceNumber] = await invoice.GetNextInvoiceNumber(Invoice.Literal_InvoiceType_Sale, 0);
        invoice.InvoiceRow[Invoice.Field_Invoice_InvoiceType_LinkCode] = Invoice.Literal_InvoiceType_Sale;
        invoice.InvoiceRow[Invoice.Field_Invoice_IssueDate] = DateTime.Today;
        invoice.InvoiceRow[Invoice.Field_Invoice_Client_LinkNo] = 4;
        invoice.InvoiceRow[Invoice.Field_Invoice_Branch_LinkNo] = 0;
        invoice.InvoiceRow[Invoice.Field_Invoice_RecordLocator] = "ABCDEF";
        invoice.AddRow(invoice.InvoiceRow);

        invoice.BookingRow[Invoice.Field_Booking_SubmitTo_LinkCode] = Invoice.Literal_SubmitTo_Supplier;
        invoice.BookingRow[Invoice.Field_Booking_Vendor_LinkNo] = 2;
        invoice.BookingRow[Invoice.Field_Booking_ConfirmNo] = "ABC123";
        invoice.BookingRow = invoice.AddRow(invoice.BookingRow);

        invoice.BookingRow[Invoice.Field_Booking_SubmitTo_LinkCode] = Invoice.Literal_SubmitTo_Supplier;
        invoice.BookingRow[Invoice.Field_Booking_Vendor_LinkNo] = 3;
        invoice.BookingRow[Invoice.Field_Booking_ConfirmNo] = "DEF456";
        invoice.AddRow(invoice.BookingRow);

        invoice.SegmentRow[Invoice.Field_Segment_IndexNo] = 1;
        invoice.AddRow(invoice.SegmentRow);

        await invoice.Save();

Dan

bi...@shelleyconsulting.com

unread,
Nov 17, 2019, 5:05:24 PM11/17/19
to TramsAPI Beta
Hi Dan,

Is there an updated dll for the sample C# project?

Dan Palley

unread,
Nov 18, 2019, 1:17:10 PM11/18/19
to TramsAPI Beta

Dan Palley

unread,
Nov 19, 2019, 1:40:24 PM11/19/19
to TramsAPI Beta
Bill,

I've published the DLL to NuGet.  If you're using Visual Studio, you can install by searching for Trams or Sabre in the package manager.  The name is Sabre.Trams.AppServer.Client.

Capture.PNG


Dan
Reply all
Reply to author
Forward
0 new messages