public static void PopulateIdentifier(Entity booking, BookingIdentifier identifier, ITracingService trace) { if (trace == null) { throw new InvalidPluginExecutionException("Tracing service is null;"); } trace.Trace("Booking Identifier - start"); if (booking == null) { throw new InvalidPluginExecutionException("Booking entity is null."); } if (identifier == null) { throw new InvalidPluginExecutionException("Booking identifier is null."); } if (identifier != null) { trace.Trace("Booking populate identifier - start"); booking[Attributes.Booking.Name] = identifier.BookingNumber; booking[Attributes.Booking.OnTourVersion] = (identifier.BookingVersionOnTour != null) ? identifier.BookingVersionOnTour : string.Empty; booking[Attributes.Booking.TourOperatorVersion] = (identifier.BookingVersionTourOperator != null) ? identifier.BookingVersionTourOperator : string.Empty; booking[Attributes.Booking.OnTourUpdatedDate] = !string.IsNullOrWhiteSpace(identifier.BookingUpdateDateOnTour) ? Convert.ToDateTime(identifier.BookingUpdateDateOnTour) : (DateTime?)null; booking[Attributes.Booking.TourOperatorUpdatedDate] = !string.IsNullOrWhiteSpace(identifier.BookingUpdateDateTourOperator) ? Convert.ToDateTime(identifier.BookingUpdateDateTourOperator) : (DateTime?)null; booking[Attributes.Booking.SourceApplication] = identifier.SourceApplication != SourceApplication.NotSpecified ? identifier.SourceApplication.ToString() : null; booking[Attributes.Booking.SourceSystem] = identifier.BookingSystem.ToString(); booking[Attributes.Booking.DealSequenceNumber] = identifier.DealSequenceNumber; booking[Attributes.Booking.ConsultationReferenceId] = (!string.IsNullOrWhiteSpace(identifier.ConsultationReference)) ? new EntityReference(EntityName.TravelPlanner, new Guid(identifier.ConsultationReference)) : null; booking[Attributes.Booking.SourceSystemId] = CommonXrm.GetSourceSystem(identifier.SourceSystem); trace.Trace("Booking populate identifier - end"); } trace.Trace("Booking Identifier - end"); }
private void DoActionsOnPostAccount(Customer customer) { if (customer == null) { return; } var accounts = GetAccountsBySourceSystemId(customer.CustomerIdentifier.CustomerId); if (accounts != null) { if (accounts.Entities.Count > 0) { payloadCustomer.Response = new XrmUpdateResponse() { Existing = true, Create = false, Id = null }; return; } } var account = AccountHelper.GetAccountEntityForCustomerPayload(customer, trace); var xrmResponse = CommonXrm.CreateEntity(account, crmService); payloadCustomer.CustomerId = xrmResponse.Id; payloadCustomer.Response = new XrmUpdateResponse() { Existing = false, Create = xrmResponse.Create, Id = xrmResponse.Id }; }
private static void PopulateEmail(Email[] emailList, ITracingService trace, FieldService fieldService) { if (fieldService == null) { return; } trace.Trace("Account populate email - start"); var email1 = emailList[0]; var email2 = emailList.Length > 1 ? emailList[1] : null; var email3 = emailList.Length > 2 ? emailList[2] : null; if (email1 != null) { trace.Trace(email1.EmailType.ToString()); trace.Trace(CommonXrm.GetEmailType(email1.EmailType).Value.ToString()); fieldService.PopulateField(Attributes.Account.EmailAddress1Type, CommonXrm.GetEmailType(email1.EmailType)); fieldService.PopulateField(Attributes.Account.EmailAddress1, email1.Address); } if (email2 != null) { trace.Trace(email2.EmailType.ToString()); trace.Trace(CommonXrm.GetEmailType(email2.EmailType).Value.ToString()); fieldService.PopulateField(Attributes.Account.EmailAddress2Type, CommonXrm.GetEmailType(email2.EmailType)); fieldService.PopulateField(Attributes.Account.EmailAddress2, email2.Address); } if (email3 != null) { trace.Trace(email3.EmailType.ToString()); trace.Trace(CommonXrm.GetEmailType(email3.EmailType).Value.ToString()); fieldService.PopulateField(Attributes.Account.EmailAddress3Type, CommonXrm.GetEmailType(email3.EmailType)); fieldService.PopulateField(Attributes.Account.EmailAddress3, email3.Address); } trace.Trace("Account populate email - end"); }
private static void PopulateIdentityInformation(CustomerIdentity identity, ITracingService trace, FieldService fieldService) { trace.Trace("Contact populate identity - start"); if (fieldService == null) { return; } if (identity == null) { return; } fieldService.PopulateField(Attributes.Contact.FirstName, identity.FirstName); fieldService.PopulateField(Attributes.Contact.LastName, identity.LastName); fieldService.PopulateField(Attributes.Contact.MiddleName, identity.MiddleName); fieldService.PopulateField(Attributes.Contact.AcademicTitle, identity.AcademicTitle); fieldService.PopulateField(Attributes.Contact.Language, CommonXrm.GetLanguage(identity.Language)); var salutation = CommonXrm.GetSalutation(identity.Salutation); if (salutation != null) { fieldService.PopulateField(Attributes.Contact.Salutation, CommonXrm.GetSalutation(identity.Salutation)); } fieldService.PopulateField(Attributes.Contact.Gender, CommonXrm.GetGender(identity.Gender)); DateTime?dateOfBirth = null; if (!string.IsNullOrWhiteSpace(identity.Birthdate)) { dateOfBirth = Convert.ToDateTime(identity.Birthdate); } fieldService.PopulateField(Attributes.Contact.Birthdate, dateOfBirth); trace.Trace("Contact populate identity - end"); }
private static void PopulatePermission(Permissions permissions, ITracingService trace, FieldService fieldService) { trace.Trace("Contact populate permission - start"); if (permissions == null) { return; } if (fieldService == null) { return; } fieldService.PopulateField(Attributes.Contact.SendMarketingByPost, CommonXrm.GetMarketingByPost(permissions.DoNotAllowMail)); fieldService.PopulateField(Attributes.Contact.MarketingByPhone, CommonXrm.GetMarketingByPhone(permissions.DoNotAllowPhoneCalls)); fieldService.PopulateField(Attributes.Contact.SendMarketingBySms, CommonXrm.GetMarketingBySms(permissions.DoNotAllowSms)); fieldService.PopulateField(Attributes.Contact.SendMarketingByEmail, CommonXrm.GetMarketingByEmail(permissions.DoNotAllowEmail)); fieldService.PopulateField(Attributes.Contact.ThomasCookMarketingConsent, CommonXrm.GetMarketingConsent(permissions.AllowMarketing)); trace.Trace("Contact populate permission - end"); }
private EntityCollection GetContactsBySourceSystemId(string customerId) { return(CommonXrm.RetrieveMultipleRecords(EntityName.Contact, new string[] { Attributes.Account.AccountId, Attributes.Contact.SourceSystemId }, new string[] { Attributes.Contact.DuplicateSourceSystemId }, new string[] { customerId }, crmService)); }
private static Entity PrepareCustomerSocialProfiles(Social socialprofile, Guid customerId, ITracingService trace) { if (socialprofile.Value == null) { return(null); } trace.Trace("Preparing Social Profile information - Start"); Entity socialprofileEntity = null; if (!string.IsNullOrWhiteSpace(socialprofile.Value)) { socialprofileEntity = new Entity(EntityName.SocialProfile, Attributes.SocialProfile.UniqueProfileId, socialprofile.Value); } if (!string.IsNullOrWhiteSpace(socialprofile.Value)) { socialprofileEntity[Attributes.SocialProfile.ProfileName] = socialprofile.Value; } if (!string.IsNullOrWhiteSpace(socialprofile.SocialType)) { socialprofileEntity[Attributes.SocialProfile.SocialChannel] = CommonXrm.GetCommunity(socialprofile.SocialType); } if (customerId != null) { socialprofileEntity[Attributes.SocialProfile.Customer] = new EntityReference(EntityName.Contact, customerId); } trace.Trace("Preparing Social Profile information - End"); return(socialprofileEntity); }
/// <summary> /// To process contact information /// </summary> /// <returns></returns> public void ProcessContact() { trace.Trace("Processing Contact information - start"); XrmResponse xrmResponse = null; if (payloadBooking.BookingInfo != null && payloadBooking.BookingInfo.Customer != null) { var customer = payloadBooking.BookingInfo.Customer; var contact = ContactHelper.GetContactEntityForBookingPayload(customer, trace); xrmResponse = CommonXrm.UpsertEntity(contact, crmService); if (xrmResponse.Create) { payloadBooking.DeleteBookingRole = true; } else { payloadBooking.DeleteBookingRole = false; } payloadBooking.CustomerId = xrmResponse.Id; trace.Trace("Processing Contact information - end"); } }
private void UpdateContacts(EntityCollection contacts, Entity contact) { if (contacts == null) { return; } if (contact == null) { return; } ExecuteTransactionRequest multipleRequest = new ExecuteTransactionRequest { Requests = new OrganizationRequestCollection(), ReturnResponses = true }; foreach (Entity existingContact in contacts.Entities) { contact[Attributes.Contact.ContactId] = existingContact.Id; var updateRequest = new UpdateRequest { Target = contact }; multipleRequest.Requests.Add(updateRequest); if (multipleRequest.Requests.Count == 500) { payloadCustomer.Response = CommonXrm.BulkUpdate(multipleRequest, crmService); multipleRequest.Requests.Clear(); } } if (multipleRequest.Requests.Count > 0) { payloadCustomer.Response = CommonXrm.BulkUpdate(multipleRequest, crmService); } }
/// <summary> /// /// </summary> public void ProcessTransport() { if (payloadBooking.BookingInfo.Services == null) { return; } if (payloadBooking.BookingInfo.Services.Transport == null) { return; } if (payloadBooking.BookingInfo.Services != null && payloadBooking.BookingInfo.Services.Transport != null) { if (payloadBooking.DeleteChildRecords) { trace.Trace("Delete Transport information - start"); ProcessRecordsToDelete(EntityName.BookingTransport, new string[] { Attributes.BookingTransport.BookingTransportId }, new string[] { Attributes.BookingAccommodation.BookingId }, new string[] { payloadBooking.BookingId }); trace.Trace("Delete Transport information - end"); } trace.Trace("Transport information - start"); var bookinginfo = payloadBooking.BookingInfo; var entityCollectionTransport = BookingTransportHelper.GetTransportEntityForBookingPayload(bookinginfo, Guid.Parse(payloadBooking.BookingId), trace); CommonXrm.BulkCreate(entityCollectionTransport, crmService); trace.Trace("Transport information - end"); } }
private static void PopulateEmail(Email[] emails, ITracingService trace, FieldService fieldService) { if (emails == null || emails.Length <= 0) { return; } if (fieldService == null) { return; } trace.Trace("Contact populate email - start"); var email1 = emails[0]; var email2 = emails.Length > 1 ? emails[1] : null; var email3 = emails.Length > 2 ? emails[2] : null; if (email1 != null) { fieldService.PopulateField(Attributes.Contact.EmailAddress1Type, CommonXrm.GetEmailType(email1.EmailType)); fieldService.PopulateField(Attributes.Contact.EmailAddress1, email1.Address); } if (email2 != null) { fieldService.PopulateField(Attributes.Contact.EmailAddress2Type, CommonXrm.GetEmailType(email2.EmailType)); fieldService.PopulateField(Attributes.Contact.EmailAddress2, email2.Address); } if (email3 != null) { fieldService.PopulateField(Attributes.Contact.EmailAddress3Type, CommonXrm.GetEmailType(email3.EmailType)); fieldService.PopulateField(Attributes.Contact.EmailAddress3, email3.Address); } trace.Trace("Contact populate email - end"); }
private static void PopulateEmail(Entity contact, Email[] emails, ITracingService trace) { if (emails == null || emails.Length <= 0) { return; } trace.Trace("Contact populate email - start"); var email1 = emails[0]; var email2 = emails.Length > 1 ? emails[1] : null; var email3 = emails.Length > 2 ? emails[2] : null; if (email1 != null) { contact[Attributes.Contact.EmailAddress1Type] = CommonXrm.GetEmailType(email1.EmailType); contact[Attributes.Contact.EmailAddress1] = (!string.IsNullOrWhiteSpace(email1.Address)) ? email1.Address : string.Empty; } if (email2 != null) { contact[Attributes.Contact.EmailAddress2Type] = CommonXrm.GetEmailType(email2.EmailType); contact[Attributes.Contact.EmailAddress2] = (!string.IsNullOrWhiteSpace(email2.Address)) ? email2.Address : string.Empty; } if (email3 != null) { contact[Attributes.Contact.EmailAddress3Type] = CommonXrm.GetEmailType(email3.EmailType); contact[Attributes.Contact.EmailAddress3] = (!string.IsNullOrWhiteSpace(email3.Address)) ? email3.Address : string.Empty; } trace.Trace("Contact populate email - end"); }
private static void PopulatePhone(Entity contact, Phone[] phoneNumbers, ITracingService trace) { if (phoneNumbers == null || phoneNumbers.Length <= 0) { return; } trace.Trace("Contact populate phone - start"); var phone1 = phoneNumbers[0]; var phone2 = phoneNumbers.Length > 1 ? phoneNumbers[1] : null; var phone3 = phoneNumbers.Length > 2 ? phoneNumbers[2] : null; if (phone1 != null) { contact[Attributes.Contact.Telephone1Type] = CommonXrm.GetPhoneType(phone1.PhoneType); contact[Attributes.Contact.Telephone1] = (!string.IsNullOrWhiteSpace(phone1.Number)) ? phone1.Number : string.Empty; } if (phone2 != null) { contact[Attributes.Contact.Telephone2Type] = CommonXrm.GetPhoneType(phone2.PhoneType); contact[Attributes.Contact.Telephone2] = (!string.IsNullOrWhiteSpace(phone2.Number)) ? phone2.Number : string.Empty; } if (phone3 != null) { contact[Attributes.Contact.Telephone3Type] = CommonXrm.GetPhoneType(phone3.PhoneType); contact[Attributes.Contact.Telephone3] = (!string.IsNullOrWhiteSpace(phone3.Number)) ? phone3.Number : string.Empty; } trace.Trace("Contact populate phone - end"); }
public bool IsBookingOnTour(Guid bookingId) { var bookingFetch = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true'> <entity name='tc_booking'> <attribute name='tc_bookingid' /> <filter type='and'> <condition attribute='tc_bookingid' operator='eq' uitype='tc_booking' value='{bookingId}' /> <condition attribute='tc_sourcesystem' operator='eq' value='{SourceSystem.OnTour}' /> <condition attribute='statecode' operator='eq' value='0' /> </filter> </entity> </fetch>"; var bookingCollection = CommonXrm.RetrieveMultipleRecordsFetchXml(bookingFetch, crmService); if (bookingCollection != null && bookingCollection.Entities.Count == 1) { return(true); } else if (bookingCollection != null && bookingCollection.Entities.Count > 1) { payloadBooking.Response.ResponseCode = ResponseDetails.ReturnErrorCode400; } payloadBooking.Response.ResponseMessage = "More than one matching booking record found in MSD with BookingId and SourceSystem OnTour"; return(false); }
public bool IsMatchedBooking(int dealSequenceNumber, string consultationReference) { payloadBooking.Response = new BookingResponse(); var bookingFetch = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true'> <entity name='tc_booking'> <attribute name='tc_bookingid' /> <attribute name='tc_name' /> <order attribute='tc_name' descending='false' /> <filter type='and'> <condition attribute='tc_dealsequencenumber' operator='eq' value='{dealSequenceNumber}' /> <condition attribute='statecode' operator='eq' value='0' /> </filter> <link-entity name='opportunity' from='opportunityid' to='tc_consultationreferenceid' alias='ad'> <filter type='and'> <condition attribute='opportunityid' operator='eq' value='{consultationReference}' /> </filter> </link-entity> </entity> </fetch>"; var bookingCollection = CommonXrm.RetrieveMultipleRecordsFetchXml(bookingFetch, crmService); if (bookingCollection != null && bookingCollection.Entities.Count == 1) { bookingId = bookingCollection.Entities[0].Id; return(true); } else if (bookingCollection != null && bookingCollection.Entities.Count > 1) { payloadBooking.Response.ResponseCode = ResponseDetails.ReturnErrorCode400; } payloadBooking.Response.ResponseMessage = "More than one matching booking record found in MSD with DealSequenceNumber and ConsultationReference"; return(false); }
public bool IsMatchedBooking(string bookingNumber, string bookingSystem) { var bookingFetch = $@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true'> <entity name='tc_booking'> <attribute name='tc_bookingid' /> <attribute name='tc_name' /> <order attribute='tc_name' descending='false' /> <filter type='and'> <condition attribute='tc_name' operator='eq' value='{bookingNumber}' /> <condition attribute='tc_sourcesystem' operator='eq' value='{bookingSystem}' /> <condition attribute='statecode' operator='eq' value='0' /> </filter> </entity> </fetch>"; var bookingCollection = CommonXrm.RetrieveMultipleRecordsFetchXml(bookingFetch, crmService); if (bookingCollection != null && bookingCollection.Entities.Count == 1) { bookingId = bookingCollection.Entities[0].Id; return(true); } else if (bookingCollection != null && bookingCollection.Entities.Count > 1) { throw new InvalidPluginExecutionException("More than one matching booking record found in MSD with BookingNumber and SourceSystem"); } return(false); }
/// <summary> /// To fetch booking, contact /// </summary> /// <param name="bookingNumber"></param> /// <param name="sourceMarket"></param> /// <param name="tourOperator"></param> /// <param name="brand"></param> /// <param name="lastName"></param> /// <param name="email"></param> /// <param name="surveyResponse"></param> private void FetchBookingContact(string bookingNumber, string sourceMarket, string tourOperator, string brand, string lastName, Entity surveyResponse) { trace.Trace("Processing FetchBookingContact - start"); var contactCondition = PrepareContactCondition(lastName); var sourceMarketCondition = PrepareSourceMarketCondition(sourceMarket); var tourOperatorCondition = PrepareTourOperatorCondition(tourOperator); var brandCondition = PrepareBrandCondition(brand); var query = $@"<fetch output-format='xml-platform' distinct='false' version='1.0' mapping='logical'> <entity name='tc_customerbookingrole'> <link-entity name='tc_booking' alias='booking' from='tc_bookingid' to='tc_bookingid'> <attribute name='tc_bookingid' /> <filter type = 'and'> <condition attribute='tc_name' operator='eq' value='{bookingNumber}' /> </filter> {sourceMarketCondition} {tourOperatorCondition} {brandCondition} </link-entity> {contactCondition} </entity> </fetch>"; var entColBookingContact = CommonXrm.RetrieveMultipleRecordsFetchXml(query, payloadSurvey.CrmService); MapBooking(surveyResponse, entColBookingContact); MapContact(surveyResponse, entColBookingContact); trace.Trace("Processing FetchBookingContact - end"); }
private static void PopulateIdentityInformation(Entity contact, CustomerIdentity identity, ITracingService trace) { trace.Trace("Contact populate identity - start"); if (identity == null) { return; } contact[Attributes.Contact.FirstName] = (!string.IsNullOrWhiteSpace(identity.FirstName)) ? identity.FirstName : string.Empty; contact[Attributes.Contact.MiddleName] = (!string.IsNullOrWhiteSpace(identity.MiddleName)) ? identity.MiddleName : string.Empty; contact[Attributes.Contact.LastName] = (!string.IsNullOrWhiteSpace(identity.LastName)) ? identity.LastName : string.Empty; contact[Attributes.Contact.AcademicTitle] = (!string.IsNullOrWhiteSpace(identity.AcademicTitle)) ? identity.AcademicTitle : string.Empty; contact[Attributes.Contact.Language] = CommonXrm.GetLanguage(identity.Language); contact[Attributes.Contact.Gender] = CommonXrm.GetGender(identity.Gender); if (!string.IsNullOrWhiteSpace(identity.Salutation)) { contact[Attributes.Contact.Salutation] = CommonXrm.GetSalutation(identity.Salutation); } DateTime?dateOfBirth = null; if (!string.IsNullOrWhiteSpace(identity.Birthdate)) { dateOfBirth = Convert.ToDateTime(identity.Birthdate); } contact[Attributes.Contact.Birthdate] = dateOfBirth; trace.Trace("Contact populate identity - end"); }
private static void PopulatePhone(Phone[] phoneList, ITracingService trace, FieldService fieldService) { if (phoneList == null || phoneList.Length <= 0) { return; } if (fieldService == null) { return; } trace.Trace("Contact populate phone - start"); var phone1 = phoneList[0]; var phone2 = phoneList.Length > 1 ? phoneList[1] : null; var phone3 = phoneList.Length > 2 ? phoneList[2] : null; if (phone1 != null) { fieldService.PopulateField(Attributes.Contact.Telephone1Type, CommonXrm.GetPhoneType(phone1.PhoneType)); fieldService.PopulateField(Attributes.Contact.Telephone1, phone1.Number); } if (phone2 != null) { fieldService.PopulateField(Attributes.Contact.Telephone2Type, CommonXrm.GetPhoneType(phone2.PhoneType)); fieldService.PopulateField(Attributes.Contact.Telephone2, phone2.Number); } if (phone3 != null) { fieldService.PopulateField(Attributes.Contact.Telephone3Type, CommonXrm.GetPhoneType(phone3.PhoneType)); fieldService.PopulateField(Attributes.Contact.Telephone3, phone3.Number); } trace.Trace("Contact populate phone - end"); }
/// <summary> /// To map Gateway information to survey record /// </summary> /// <param name="surveyResponse"></param> /// <param name="response"></param> private void MapGateway(Entity surveyResponse, Response response) { trace.Trace("Processing MapGateway - start"); surveyResponse[Attributes.SurveyResponse.GatewayId] = null; if (response.Answers == null || response.Answers.Count == 0) { return; } var gatewayCode = AnswerHelper.GetTcdisDestinationAirport(response.Answers, payloadSurvey.Trace); if (string.IsNullOrWhiteSpace(gatewayCode)) { return; } var query = $@"<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'> <entity name='tc_gateway'> <attribute name='tc_gatewayid'/> <filter type='and'> <condition attribute='tc_iata' value='{gatewayCode}' operator='eq'/> </filter> </entity> </fetch>"; var entColGateways = CommonXrm.RetrieveMultipleRecordsFetchXml(query, payloadSurvey.CrmService); if (entColGateways == null || entColGateways.Entities.Count == 0) { return; } surveyResponse.Attributes[Attributes.SurveyResponse.GatewayId] = new EntityReference(EntityName.Gateway, entColGateways.Entities[0].Id); trace.Trace("Processing MapGateway - end"); }
public static void PopulateGeneralFields(Entity booking, BookingGeneral general, ITracingService trace) { if (trace == null) { throw new InvalidPluginExecutionException("Tracing service is null;"); } trace.Trace("Booking general - start"); if (booking == null) { throw new InvalidPluginExecutionException("Booking entity is null."); } if (general == null) { throw new InvalidPluginExecutionException("Booking general information is null."); } if (general != null) { trace.Trace("Booking populate general - start"); booking[Attributes.Booking.BookingDate] = (!string.IsNullOrWhiteSpace(general.BookingDate)) ? Convert.ToDateTime(general.BookingDate) : (DateTime?)null; booking[Attributes.Booking.DepartureDate] = (!string.IsNullOrWhiteSpace(general.DepartureDate)) ? Convert.ToDateTime(general.DepartureDate) : (DateTime?)null; booking[Attributes.Booking.ReturnDate] = (!string.IsNullOrWhiteSpace(general.ReturnDate)) ? Convert.ToDateTime(general.ReturnDate) : (DateTime?)null; booking[Attributes.Booking.DestinationGatewayId] = (!string.IsNullOrWhiteSpace(general.Destination)) ? new EntityReference(EntityName.Gateway, new Guid(general.Destination)) : null; booking[Attributes.Booking.TourOperatorId] = (!string.IsNullOrWhiteSpace(general.ToCode)) ? new EntityReference(EntityName.TourOperator, new Guid(general.ToCode)) : null; booking[Attributes.Booking.BrandId] = (!string.IsNullOrWhiteSpace(general.Brand)) ? new EntityReference(EntityName.Brand, new Guid(general.Brand)) : null; booking[Attributes.Booking.BrochureCode] = (!string.IsNullOrWhiteSpace(general.BrochureCode)) ? general.BrochureCode : string.Empty; booking[Attributes.Booking.IsLateBooking] = general.IsLateBooking; booking[Attributes.Booking.NumberOfParticipants] = general.NumberOfParticipants; booking[Attributes.Booking.NumberOfAdults] = general.NumberOfAdults; booking[Attributes.Booking.NumberOfChildren] = general.NumberOfChildren; booking[Attributes.Booking.NumberOfInfants] = general.NumberOfInfants; booking[Attributes.Booking.TravelAmount] = new Money(general.TravelAmount); if (!string.IsNullOrWhiteSpace(general.Currency)) { booking[Attributes.Booking.TransactionCurrencyId] = new EntityReference(EntityName.Currency, new Guid(general.Currency)); } booking[Attributes.Booking.HasSourceMarketComplaint] = general.HasComplaint; booking[Attributes.Booking.NumberOfDealsOnConsultation] = general.NumberOfDealsOnConsultation; booking[Attributes.Booking.AmountDueDate] = (!string.IsNullOrWhiteSpace(general.AmountDueDate)) ? Convert.ToDateTime(general.AmountDueDate) : (DateTime?)null; booking[Attributes.Booking.ProductTypeCode] = CommonXrm.GetProductTypeCode(general.ProductTypeCode); booking[Attributes.Booking.ProductTypeCodeDescription] = (!string.IsNullOrWhiteSpace(general.ProductTypeCodeDescription)) ? general.ProductTypeCodeDescription : null; booking[Attributes.Booking.OperatorCode] = (!string.IsNullOrWhiteSpace(general.OperatorCode)) ? general.OperatorCode : string.Empty; booking[Attributes.Booking.OperatorCodeDescription] = (!string.IsNullOrWhiteSpace(general.OperatorCodeDescription)) ? general.OperatorCodeDescription : string.Empty; booking[Attributes.Booking.TotalDueAmount] = new Money(general.TotalDueAmount); booking[Attributes.Booking.TotalPaid] = new Money(general.TotalPaid); booking[Attributes.Booking.DepositAmount] = new Money(general.DepositAmount); booking[Attributes.Booking.IsLowDeposit] = general.IsLowDeposit; booking[Attributes.Booking.DepositDueDate] = Convert.ToDateTime(general.DepositDueDate); booking[Attributes.Booking.CancellationDate] = Convert.ToDateTime(general.CancellationDate); booking[Attributes.Booking.NumberOfSeniorCitizens] = general.NumberOfSeniorCitizens; trace.Trace("Booking populate general - end"); } trace.Trace("Booking general - end"); }
private static Entity PrepareBookingTransport(Booking bookinginfo, Transport transport, Guid bookingId, ITracingService trace) { trace.Trace("Transport populate fields - start"); var transportEntity = new Entity(EntityName.BookingTransport); SetNameFor(transport, bookinginfo, transportEntity); if (!string.IsNullOrWhiteSpace(transport.TransportCode)) { transportEntity[Attributes.BookingTransport.TransportCode] = transport.TransportCode; } if (!string.IsNullOrWhiteSpace(transport.TransportDescription)) { transportEntity[Attributes.BookingTransport.Description] = transport.TransportDescription; } transportEntity[Attributes.BookingTransport.Order] = transport.Order; if (!string.IsNullOrWhiteSpace(transport.StartDate)) { transportEntity[Attributes.BookingTransport.StartDateAndTime] = DateTime.Parse(transport.StartDate); } if (!string.IsNullOrWhiteSpace(transport.EndDate)) { transportEntity[Attributes.BookingTransport.EndDateAndTime] = DateTime.Parse(transport.EndDate); } transportEntity[Attributes.BookingTransport.TransferType] = CommonXrm.GetTransferType(transport.TransferType); if (!string.IsNullOrWhiteSpace(transport.DepartureAirport)) { transportEntity[Attributes.BookingTransport.DepartureGatewayId] = new EntityReference(EntityName.Gateway, new Guid(transport.DepartureAirport)); } if (!string.IsNullOrWhiteSpace(transport.ArrivalAirport)) { transportEntity[Attributes.BookingTransport.ArrivalGatewayId] = new EntityReference(EntityName.Gateway, new Guid(transport.ArrivalAirport)); } if (!string.IsNullOrWhiteSpace(transport.CarrierCode)) { transportEntity[Attributes.BookingTransport.CarrierCode] = transport.CarrierCode; } if (!string.IsNullOrWhiteSpace(transport.FlightNumber)) { transportEntity[Attributes.BookingTransport.FlightNumber] = transport.FlightNumber; } if (!string.IsNullOrWhiteSpace(transport.FlightIdentifier)) { transportEntity[Attributes.BookingTransport.FlightIdentifier] = transport.FlightIdentifier; } transportEntity[Attributes.BookingTransport.NumberOfParticipants] = transport.NumberOfParticipants; transportEntity[Attributes.BookingTransport.BookingId] = new EntityReference(EntityName.Booking, bookingId); transportEntity[Attributes.BookingTransport.Participants] = BookingHelper.PrepareTravelParticipantsInfoForChildRecords(bookinginfo.TravelParticipant, trace, transport.TravelParticipantAssignment); transportEntity[Attributes.Booking.Remarks] = RemarksHelper.GetRemarksTextFromPayload(transport.Remark); transportEntity[Attributes.BookingTransport.TransportType] = CommonXrm.GetTransportType(transport.TransportType); trace.Trace("Transport populate fields - end"); return(transportEntity); }
public static Entity GetContactEntityForCustomerPayload(Customer customer, ITracingService trace) { if (trace == null) { throw new InvalidPluginExecutionException("Tracing service is null;"); } trace.Trace("Contact populate fields - start"); if (customer == null) { throw new InvalidPluginExecutionException("Customer payload is null."); } if (customer.CustomerIdentifier == null) { throw new InvalidPluginExecutionException("Customer Identifier could not be retrieved from payload."); } if (string.IsNullOrWhiteSpace(customer.CustomerIdentifier.CustomerId)) { throw new InvalidPluginExecutionException("Customer Identifier could not be retrieved from payload."); } Entity contact = new Entity(EntityName.Contact); var sourceSystemID = (!string.IsNullOrWhiteSpace(customer.CustomerIdentifier.CustomerId)) ? customer.CustomerIdentifier.CustomerId : string.Empty; contact[Attributes.Contact.SourceSystemId] = sourceSystemID; contact[Attributes.Contact.DuplicateSourceSystemId] = sourceSystemID; var sourceMarket = (!string.IsNullOrWhiteSpace(customer.CustomerIdentifier.SourceMarket)) ? new EntityReference(EntityName.Country, new Guid(customer.CustomerIdentifier.SourceMarket)) : null; contact[Attributes.Contact.SourceMarketId] = sourceMarket; PopulateIdentityInformation(contact, customer.CustomerIdentity, trace); PopulateAddress(contact, customer.Address, trace); PopulateEmail(contact, customer.Email, trace); PopulatePhone(contact, customer.Phone, trace); PopulatePermission(contact, customer.Permissions, trace); if (customer.CustomerGeneral != null) { contact[Attributes.Contact.StatusCode] = CommonXrm.GetCustomerStatus(customer.CustomerGeneral.CustomerStatus); } if (customer.Additional != null) { contact[Attributes.Contact.Segment] = CommonXrm.GetSegment(customer.Additional.Segment); DateTime?dateOfDeath = null; if (!string.IsNullOrWhiteSpace(customer.Additional.DateOfDeath)) { dateOfDeath = Convert.ToDateTime(customer.Additional.DateOfDeath); } contact[Attributes.Contact.DateOfDeath] = dateOfDeath; } trace.Trace("Contact populate fields - end"); return(contact); }
private static Entity PrepareBookingAccommodation(Booking bookinginfo, Accommodation accommodation, Guid bookingId, ITracingService trace) { trace.Trace("Preparing Booking Accommodation information - Start"); var accommodationEntity = new Entity(EntityName.BookingAccommodation); if (accommodation.AccommodationCode != null) { accommodationEntity[Attributes.BookingAccommodation.SourceMarketHotelCode] = accommodation.AccommodationCode; } if (!string.IsNullOrEmpty(accommodation.GroupAccommodationCode)) { accommodationEntity[Attributes.BookingAccommodation.HotelId] = new EntityReference(EntityName.Hotel, new Guid(accommodation.GroupAccommodationCode)); } SetNameFor(accommodation, bookinginfo, accommodationEntity); accommodationEntity[Attributes.BookingAccommodation.Order] = accommodation.Order.ToString(); if (!string.IsNullOrWhiteSpace(accommodation.StartDate)) { accommodationEntity[Attributes.BookingAccommodation.StartDateAndTime] = DateTime.Parse(accommodation.StartDate); } if (!string.IsNullOrWhiteSpace(accommodation.EndDate)) { accommodationEntity[Attributes.BookingAccommodation.EndDateAndTime] = DateTime.Parse(accommodation.EndDate); } if (!string.IsNullOrWhiteSpace(accommodation.RoomType)) { accommodationEntity[Attributes.BookingAccommodation.RoomType] = accommodation.RoomType; } accommodationEntity[Attributes.BookingAccommodation.BoardType] = CommonXrm.GetBoardType(accommodation.BoardType); accommodationEntity[Attributes.BookingAccommodation.HasSharedRoom] = accommodation.HasSharedRoom; accommodationEntity[Attributes.BookingAccommodation.NumberOfParticipants] = accommodation.NumberOfParticipants; accommodationEntity[Attributes.BookingAccommodation.NumberOfRooms] = accommodation.NumberOfRooms; accommodationEntity[Attributes.BookingAccommodation.WithTransfer] = accommodation.WithTransfer; accommodationEntity[Attributes.BookingAccommodation.IsExternalService] = accommodation.IsExternalService; accommodationEntity[Attributes.BookingAccommodation.ExternalServiceCode] = CommonXrm.GetExternalServiceCode(accommodation.ExternalServiceCode); accommodationEntity[Attributes.BookingAccommodation.NotificationRequired] = accommodation.NotificationRequired; accommodationEntity[Attributes.BookingAccommodation.NeedTourGuideAssignment] = accommodation.NeedsTourGuideAssignment; accommodationEntity[Attributes.BookingAccommodation.ExternalTransfer] = accommodation.IsExternalTransfer; accommodationEntity[Attributes.BookingAccommodation.TransferServiceLevel] = CommonXrm.GetTransferServiceLevel(accommodation.TransferServiceLevel); if (!string.IsNullOrWhiteSpace(accommodation.AccommodationDescription)) { accommodationEntity[Attributes.BookingAccommodation.SourceMarketHotelName] = accommodation.AccommodationDescription; } accommodationEntity[Attributes.BookingAccommodation.BookingId] = new EntityReference(EntityName.Booking, bookingId); accommodationEntity[Attributes.BookingAccommodation.Participants] = BookingHelper.PrepareTravelParticipantsInfoForChildRecords(bookinginfo.TravelParticipant, trace, accommodation.TravelParticipantAssignment); accommodationEntity[Attributes.Booking.StateCode] = new OptionSetValue((int)Statecode.Active); accommodationEntity[Attributes.Booking.StatusCode] = CommonXrm.GetAccommodationStatus(accommodation.Status); accommodationEntity[Attributes.Booking.Remarks] = RemarksHelper.GetRemarksTextFromPayload(accommodation.Remark); trace.Trace("Preparing Booking Transport information - End"); return(accommodationEntity); }
public static void PopulatePhone(Entity account, Phone[] phoneList, ITracingService trace) { if (trace == null) { throw new InvalidPluginExecutionException("Tracing service is null;"); } trace.Trace("Account populate phone - start"); if (account == null) { throw new InvalidPluginExecutionException("Account entity is null;"); } if (phoneList == null || phoneList.Length == 0) { ClearPhoneList(account); return; } var phone1 = phoneList[0]; var phone2 = phoneList.Length > 1 ? phoneList[1] : ClearPhone2(account); var phone3 = phoneList.Length > 2 ? phoneList[2] : ClearPhone3(account); trace.Trace("phone 1"); if (phone1 == null) { return; } account[Attributes.Account.Telephone1Type] = CommonXrm.GetPhoneType(phone1.PhoneType); account[Attributes.Account.Telephone1] = (!string.IsNullOrWhiteSpace(phone1.Number)) ? phone1.Number : string.Empty; trace.Trace("phone 2"); if (phone2 == null) { return; } account[Attributes.Account.Telephone2Type] = CommonXrm.GetPhoneType(phone2.PhoneType); account[Attributes.Account.Telephone2] = (!string.IsNullOrWhiteSpace(phone2.Number)) ? phone2.Number : string.Empty; trace.Trace("phone 3"); if (phone3 == null) { return; } account[Attributes.Account.Telephone3Type] = CommonXrm.GetPhoneType(phone2.PhoneType); account[Attributes.Account.Telephone3] = (!string.IsNullOrWhiteSpace(phone3.Number)) ? phone3.Number : string.Empty; trace.Trace("Account populate phone - end"); }
private static void PopulatePermission(Entity contact, Permissions permissions, ITracingService trace) { if (permissions == null) { return; } trace.Trace("Contact populate permission - start"); contact[Attributes.Contact.SendMarketingByPost] = CommonXrm.GetMarketingByPost(permissions.DoNotAllowMail); contact[Attributes.Contact.MarketingByPhone] = CommonXrm.GetMarketingByPhone(permissions.DoNotAllowPhoneCalls); contact[Attributes.Contact.SendMarketingBySms] = CommonXrm.GetMarketingBySms(permissions.DoNotAllowSms); contact[Attributes.Contact.SendMarketingByEmail] = CommonXrm.GetMarketingByEmail(permissions.DoNotAllowMail); contact[Attributes.Contact.ThomasCookMarketingConsent] = CommonXrm.GetMarketingConsent(permissions.AllowMarketing); trace.Trace("Contact populate permission - end"); }
public static void PopulateEmail(Entity account, Email[] emailList, ITracingService trace) { if (trace == null) { throw new InvalidPluginExecutionException("Tracing service is null;"); } trace.Trace("Account populate email - start"); if (account == null) { throw new InvalidPluginExecutionException("Account entity is null;"); } if (emailList == null || emailList.Length == 0) { ClearEmailList(account); return; } var email1 = emailList[0]; var email2 = emailList.Length > 1 ? emailList[1] : ClearEmail2(account); var email3 = emailList.Length > 2 ? emailList[2] : ClearEmail3(account); trace.Trace("email 1"); if (email1 == null) { return; } account[Attributes.Account.EmailAddress1] = (!string.IsNullOrWhiteSpace(email1.Address)) ? email1.Address : string.Empty; account[Attributes.Account.EmailAddress1Type] = CommonXrm.GetEmailType(email1.EmailType); trace.Trace("email 2"); if (email2 == null) { return; } account[Attributes.Account.EmailAddress2] = (!string.IsNullOrWhiteSpace(email2.Address)) ? email2.Address : string.Empty; account[Attributes.Account.EmailAddress2Type] = CommonXrm.GetEmailType(email2.EmailType); trace.Trace("email 3"); if (email3 == null) { return; } account[Attributes.Account.EmailAddress3] = (!string.IsNullOrWhiteSpace(email3.Address)) ? email3.Address : string.Empty; account[Attributes.Account.EmailAddress3Type] = CommonXrm.GetEmailType(email3.EmailType); trace.Trace("Account populate email - end"); }
/// <summary> /// To create Feedback records /// </summary> /// <param name="answersToCreate"></param> /// <param name="surveyId"></param> private void CreateFeedback(List <Answer> answersToCreate, Guid surveyId) { trace.Trace("Processing CreateFeedback - start"); if (answersToCreate == null || answersToCreate.Count == 0 || surveyId == Guid.Empty) { return; } for (int i = 0; i < answersToCreate.Count; i++) { var feedbackEntity = AnswerHelper.GetFeedbackEntityFromPayload(answersToCreate[i], payloadSurvey.Trace); feedbackEntity.Attributes[Attributes.SurveyResponseFeedback.SurveyFeedbackId] = new EntityReference(EntityName.SurveyResponse, surveyId); CommonXrm.CreateEntity(feedbackEntity, payloadSurvey.CrmService); } trace.Trace("Processing CreateFeedback - end"); }
private static void PopulatePhone(Entity contact, Phone[] phoneNumbers, ITracingService trace) { trace.Trace("Contact populate phone - start"); if (trace == null) { throw new InvalidPluginExecutionException("Tracing service is null;"); } if (contact == null) { throw new InvalidPluginExecutionException("Populate Phone: contact entity is null."); } if (phoneNumbers == null || phoneNumbers.Length == 0) { ClearPhoneList(contact); return; } ; var phone1 = phoneNumbers[0]; var phone2 = phoneNumbers.Length > 1 ? phoneNumbers[1] : ClearPhone2(contact); var phone3 = phoneNumbers.Length > 2 ? phoneNumbers[2] : ClearPhone3(contact); trace.Trace("phone 1"); if (phone1 == null) { return; } contact[Attributes.Contact.Telephone1Type] = CommonXrm.GetPhoneType(phone1.PhoneType); contact[Attributes.Contact.Telephone1] = (!string.IsNullOrWhiteSpace(phone1.Number)) ? phone1.Number:string.Empty; trace.Trace("phone 2"); if (phone2 == null) { return; } contact[Attributes.Contact.Telephone2Type] = CommonXrm.GetPhoneType(phone2.PhoneType); contact[Attributes.Contact.Telephone2] = (!string.IsNullOrWhiteSpace(phone2.Number)) ? phone2.Number : string.Empty; trace.Trace("phone 3"); if (phone3 == null) { return; } contact[Attributes.Contact.Telephone3Type] = CommonXrm.GetPhoneType(phone3.PhoneType); contact[Attributes.Contact.Telephone3] = (!string.IsNullOrWhiteSpace(phone3.Number)) ? phone3.Number : string.Empty; trace.Trace("Contact populate phone - end"); }
/// <summary> /// /// </summary> public void ProcessBookingRole() { if (payloadBooking.DeleteBookingRole) { trace.Trace("Delete Booking Roles information - start"); ProcessRecordsToDelete(EntityName.CustomerBookingRole, new string[] { Attributes.CustomerBookingRole.CustomerBookingRoleId }, new string[] { Attributes.CustomerBookingRole.BookingId }, new string[] { payloadBooking.BookingId }); trace.Trace("Delete Booking Roles information - end"); } trace.Trace("Booking Roles information - start"); if (string.IsNullOrWhiteSpace(payloadBooking.CustomerId)) { return; } if (payloadBooking.BookingInfo.Customer.CustomerGeneral.CustomerType == CustomerType.NotSpecified) { trace.Trace("Customer type has not been specified."); return; } if (payloadBooking.Response.Created || payloadBooking.DeleteBookingRole) { Entity entityBookingRole = new Entity(EntityName.CustomerBookingRole); entityBookingRole[Attributes.CustomerBookingRole.BookingId] = new EntityReference(EntityName.Booking, new Guid(payloadBooking.BookingId)); if (payloadBooking.BookingInfo.Customer.CustomerGeneral.CustomerType == CustomerType.Company) { entityBookingRole[Attributes.CustomerBookingRole.Customer] = new EntityReference(EntityName.Account, new Guid(payloadBooking.CustomerId)); } else { entityBookingRole[Attributes.CustomerBookingRole.Customer] = new EntityReference(EntityName.Contact, new Guid(payloadBooking.CustomerId)); } EntityCollection entityCollection = new EntityCollection(); entityCollection.Entities.Add(entityBookingRole); CommonXrm.BulkCreate(entityCollection, crmService); } trace.Trace("Booking Roles information - end"); }