public static Entity GetBookingEntityFromPayload(Booking booking, ITracingService trace) { if (trace == null) { throw new InvalidPluginExecutionException("Trace service is null;"); } trace.Trace("Booking populate fields - start"); if (booking == null) { throw new InvalidPluginExecutionException("Booking is null."); } if (booking.BookingIdentifier == null) { throw new InvalidPluginExecutionException("Booking identifier is null."); } if (booking.BookingIdentifier.BookingNumber == null || string.IsNullOrWhiteSpace(booking.BookingIdentifier.BookingNumber)) { throw new InvalidPluginExecutionException("Booking Number should not be null."); } var indexCollection = new KeyAttributeCollection(); indexCollection.Add(Attributes.Booking.Name, booking.BookingIdentifier.BookingNumber); indexCollection.Add(Attributes.Booking.SourceSystem, booking.BookingIdentifier.BookingSystem.ToString()); Entity bookingEntity = new Entity(EntityName.Booking, indexCollection); PopulateIdentifier(bookingEntity, booking.BookingIdentifier, trace); PopulateIdentity(bookingEntity, booking.BookingIdentity, trace); PopulateGeneralFields(bookingEntity, booking.BookingGeneral, trace); PopulateDurationFrom(booking, bookingEntity, trace); bookingEntity[Attributes.Booking.Participants] = PrepareTravelParticipantsInfo(booking.TravelParticipant, trace); bookingEntity[Attributes.Booking.ParticipantRemarks] = PrepareTravelParticipantsRemarks(booking.TravelParticipant, trace); if (!string.IsNullOrWhiteSpace(booking.DestinationId)) { bookingEntity[Attributes.Booking.DestinationId] = new EntityReference(EntityName.Region, new Guid(booking.DestinationId)); } else { bookingEntity[Attributes.Booking.DestinationId] = null; } if (booking.BookingIdentifier != null) { if (!string.IsNullOrWhiteSpace(booking.Owner)) { bookingEntity[Attributes.Booking.Owner] = new EntityReference(EntityName.Team, new Guid(booking.Owner)); } } PopulateServices(bookingEntity, booking.Services, trace); bookingEntity[Attributes.Booking.SourceMarketId] = (booking.BookingIdentifier.SourceMarket != null) ? new EntityReference(EntityName.Country , new Guid(booking.BookingIdentifier.SourceMarket)) : null; bookingEntity[Attributes.Booking.StateCode] = new OptionSetValue((int)Statecode.Active); bookingEntity[Attributes.Booking.StatusCode] = CommonXrm.GetBookingStatus(booking.BookingGeneral.BookingStatus); bookingEntity[Attributes.Booking.Remarks] = RemarksHelper.GetRemarksTextFromPayload(booking.Remark); trace.Trace("Booking populate fields - end"); return(bookingEntity); }