public static List <string> Needs_update_in_crm(crm.Aftale crm_aftale, of.data.Agreement of_agreement) { List <string> parameters = new List <string>(); Mapping_update_helper.Add_if_unequal(parameters, "nrq_beloeb", crm_aftale.nrq_beloeb?.Value, of_agreement.Amount); Mapping_update_helper.Add_if_unequal(parameters, "nrq_betalingsform", crm_aftale.nrq_betalingsform, of_agreement.Payment_type); Mapping_update_helper.Add_if_unequal(parameters, "nrq_amounttype", crm_aftale.nrq_amounttype.SelectedValue, of_agreement.Amount_type); Mapping_update_helper.Add_if_unequal(parameters, "nrq_frequency", crm_aftale.nrq_frequency.SelectedValue, of_agreement.Frequency); Mapping_update_helper.Add_if_unequal(parameters, "nrq_of_contact_id", crm_aftale.nrq_of_contact_id, of_agreement.Contact_id); Mapping_update_helper.Add_if_unequal(parameters, "nrq_of_id", crm_aftale.nrq_of_id, of_agreement.Of_id); Mapping_update_helper.Add_if_unequal(parameters, "nrq_of_project_id", crm_aftale.nrq_of_project_id, of_agreement.Project_id); Mapping_update_helper.Add_if_unequal(parameters, "nrq_of_subscription_id", crm_aftale.nrq_of_subscription_id, of_agreement.Subscription_id); Mapping_update_helper.Add_if_unequal(parameters, "nrq_paymentmedia", crm_aftale.nrq_paymentmedia?.SelectedValue, of_agreement.Payment_media_type); Mapping_update_helper.Add_if_unequal(parameters, "nrq_type", crm_aftale.nrq_type, of_agreement.Payment_media_type); Mapping_update_helper.Add_if_unequal(parameters, "nrq_agreementstarttype", crm_aftale.nrq_agreementstarttype, of_agreement.Agreement_start_type); Mapping_update_helper.Add_if_unequal(parameters, "nrq_startdato", crm_aftale.nrq_startdato, of_agreement.Agreement_start_ts_value); Mapping_update_helper.Add_if_unequal(parameters, "nrq_slutdato", crm_aftale.nrq_slutdato, of_agreement.Last_payment_ts_value); Mapping_update_helper.Add_if_unequal(parameters, "nrq_chargedate", crm_aftale.nrq_chargedate, of_agreement.Charge_ts_value); Mapping_update_helper.Add_if_unequal(parameters, "nrq_state", crm_aftale.nrq_state, of_agreement.State); Mapping_update_helper.Add_if_other_exists(parameters, "nrq_of_subscription_id", "nrq_subscription"); Mapping_update_helper.Add_if_other_exists(parameters, "nrq_of_contact_id", "nrq_bidragyder"); return(parameters); }
private void Create_or_update_associated_entities(crm.Indbetaling crm_indbetaling, of.data.Payment of_indbetaling) { if (of_indbetaling.Agreement_id.HasValue) { of.data.Agreement of_aftale = _of_connection.Agreement.Get(of_indbetaling.Agreement_id.Value); crm.Aftale crm_aftale = Create_or_update_one_aftale_in_crm(of_aftale); crm_indbetaling.Nrq_betalingsaftale = new EntityReference("new_indbetaling", crm_aftale.Id); //_tracingService.Trace($"connecting aftale {crm_aftale.Id} to indbetaling {crm_indbetaling.Id}"); } else { //_tracingService.Trace($"no aftale on indbetaling {crm_indbetaling.Id}"); } if (of_indbetaling.Contact_id.HasValue) { of.data.Contact of_contact = _of_connection.Contact.Get(of_indbetaling.Contact_id.Value); crm.Contact crm_contact = Create_or_update_one_contact_in_crm(of_indbetaling.Contact_id, of_contact); crm_indbetaling.Nrq_indbetaler = new EntityReference("contact", crm_contact.Id); //_tracingService.Trace($"connecting contact {crm_contact.Id} to indbetaling {crm_indbetaling.Id}"); } else { //_tracingService.Trace($"no contact on indbetaling {crm_indbetaling.Id}"); } crm_indbetaling.Set_indbetaling_type_from_of_project_id(of_indbetaling.Project_id); }
private void Add_subscription_to_aftale(crm.Aftale crm_aftale, of.data.Agreement of_agreement) { if (of_agreement.Subscription_id.HasValue == false) { return; } of.data.Subscription of_subscription = _of_connection.Subscription.Get(of_agreement.Subscription_id.Value); crm.Abonnement crm_subscription = Create_or_update_one_abonnement_in_crm(of_subscription); crm_aftale.nrq_subscription = new EntityReference("nrq_subscription", crm_subscription.Id); }
public void Update_agreements_in_crm_from_of_data() { of.connector.Agreements agreements = _of_connection.Get_agreements(); foreach (int id in agreements) { of.data.Agreement of_aftale = _of_connection.Agreement.Get(id); Create_or_update_one_aftale_in_crm(of_aftale); //todo remove break; } }
private crm.Aftale Create_crm_aftale(of.data.Agreement of_agreement) { crm.Aftale crm_aftale = new crm.Aftale(_service, _tracingService); Mapping.Aftale.To_crm(crm_aftale, of_agreement, _tracingService); Add_contact_to_aftale(crm_aftale, of_agreement); Add_subscription_to_aftale(crm_aftale, of_agreement); crm_aftale.Create(); return(crm_aftale); }
private void Create_of_aftale(crm.Aftale crm_aftale) { of.data.Agreement of_aftale = new of.data.Agreement(); Mapping.Aftale.To_of(crm_aftale, of_aftale); crm.Contact crm_contact = Get_crm_contact_from_crm_aftale(crm_aftale); if (crm_contact != null) { Get_or_create_of_contact(crm_contact); } _of_connection.Agreement.Post(of_aftale); }
private void Update_of_aftale(crm.Aftale crm_aftale, of.data.Agreement of_aftale) { List <string> parameters_to_update = Mapping.Aftale.Needs_update_in_of(crm_aftale, of_aftale); if (parameters_to_update.Any() == false) { return; } Mapping.Aftale.To_of(crm_aftale, of_aftale); Trace_of("Patch", parameters_to_update); _of_connection.Agreement.Patch(of_aftale.Of_id.Value, of_aftale, parameters_to_update); }
public crm.Aftale Create_or_update_one_aftale_in_crm(of.data.Agreement of_aftale) { crm.Aftale crm_aftale = new crm.Aftale(_service, _tracingService); crm_aftale.Get_by_of_id(of_aftale.Of_id.Value); if (crm_aftale.CrmEntity == null) { crm_aftale = Create_crm_aftale(of_aftale); } else { Update_aftale_in_crm(crm_aftale, of_aftale); } return(crm_aftale); }
public static void To_of(crm.Aftale crm_aftale, of.data.Agreement of_agreement) { of_agreement.Amount = (int)crm_aftale.nrq_beloeb.Value; of_agreement.Payment_type = crm_aftale.nrq_betalingsform; of_agreement.Frequency = crm_aftale.nrq_frequency.SelectedValue; of_agreement.Crm_id = crm_aftale.Id.ToString().ToLower(); of_agreement.Amount_type = crm_aftale.nrq_amounttype.SelectedValue; of_agreement.Currency = "208"; of_agreement.Payment_media = crm_aftale.nrq_paymentmedia.SelectedValue; of_agreement.Payment_media_type = crm_aftale.nrq_type; of_agreement.Project_id = crm_aftale.nrq_of_project_id; of_agreement.State = crm_aftale.nrq_state; of_agreement.Agreement_start_type = crm_aftale.nrq_agreementstarttype; of_agreement.Agreement_start_ts_value = crm_aftale.nrq_startdato; of_agreement.Last_payment_ts_value = crm_aftale.nrq_slutdato; of_agreement.Charge_ts_value = crm_aftale.nrq_chargedate; }
public static void To_crm(crm.Aftale crm_aftale, of.data.Agreement of_agreement, ITracingService tracingService) { crm_aftale.nrq_beloeb = new Microsoft.Xrm.Sdk.Money((decimal)of_agreement.Amount); crm_aftale.nrq_betalingsform = of_agreement.Payment_type; crm_aftale.nrq_amounttype.Select(of_agreement.Amount_type, tracingService); crm_aftale.nrq_frequency.Select(of_agreement.Frequency, tracingService); crm_aftale.nrq_of_contact_id = of_agreement.Contact_id; crm_aftale.nrq_of_id = of_agreement.Of_id; crm_aftale.nrq_of_project_id = of_agreement.Project_id; crm_aftale.nrq_of_subscription_id = of_agreement.Subscription_id; crm_aftale.nrq_paymentmedia.Select(of_agreement.Payment_media, tracingService); crm_aftale.nrq_type = of_agreement.Payment_media_type?.ToString(); crm_aftale.nrq_state = of_agreement.State; crm_aftale.nrq_agreementstarttype = of_agreement.Agreement_start_type; crm_aftale.nrq_startdato = of_agreement.Agreement_start_ts_value; crm_aftale.nrq_slutdato = of_agreement.Last_payment_ts_value; crm_aftale.nrq_chargedate = of_agreement.Charge_ts_value; }
public void Create_or_update_one_in_of(crm.Aftale crm_aftale) { of.data.Agreement of_aftale = null; if (string.IsNullOrWhiteSpace(crm_aftale.nrq_type) == false && int.TryParse(crm_aftale.nrq_type, out int of_id)) { of_aftale = _of_connection.Agreement.Get(of_id); } if (of_aftale == null) { Create_of_aftale(crm_aftale); } else { Update_of_aftale(crm_aftale, of_aftale); } }
public static List <string> Needs_update_in_of(crm.Aftale crm_aftale, of.data.Agreement of_agreement) { List <string> parameters = new List <string>(); Mapping_update_helper.Add_if_unequal(parameters, "Amount", crm_aftale.nrq_beloeb?.Value, of_agreement.Amount); Mapping_update_helper.Add_if_unequal(parameters, "payment_type", crm_aftale.nrq_betalingsform, of_agreement.Payment_type); Mapping_update_helper.Add_if_unequal(parameters, "Amount_type", crm_aftale.nrq_amounttype.SelectedValue, of_agreement.Amount_type); Mapping_update_helper.Add_if_unequal(parameters, "Frequency", crm_aftale.nrq_frequency.SelectedValue, of_agreement.Frequency); Mapping_update_helper.Add_if_unequal(parameters, "Project_id", crm_aftale.nrq_of_project_id, of_agreement.Project_id); Mapping_update_helper.Add_if_unequal(parameters, "Payment_media", crm_aftale.nrq_paymentmedia.SelectedValue, of_agreement.Payment_media); Mapping_update_helper.Add_if_unequal(parameters, "Payment_media_type", crm_aftale.nrq_type, of_agreement.Payment_media_type); Mapping_update_helper.Add_if_unequal(parameters, "State", crm_aftale.nrq_state, of_agreement.State); Mapping_update_helper.Add_if_unequal(parameters, "Crm_id", crm_aftale.Id.ToString().ToLower(), of_agreement.Crm_id); Mapping_update_helper.Add_if_unequal(parameters, "Agreement_start_type", crm_aftale.nrq_agreementstarttype, of_agreement.Agreement_start_type); Mapping_update_helper.Add_if_unequal(parameters, "Agreement_start_ts_value", crm_aftale.nrq_startdato, of_agreement.Agreement_start_ts_value); Mapping_update_helper.Add_if_unequal(parameters, "Last_payment_ts_value", crm_aftale.nrq_slutdato, of_agreement.Last_payment_ts_value); Mapping_update_helper.Add_if_unequal(parameters, "Charge_ts_value", crm_aftale.nrq_chargedate, of_agreement.Charge_ts_value); return(parameters); }
private bool Add_contact_to_aftale(crm.Aftale crm_aftale, of.data.Agreement of_aftale) { if (of_aftale.Contact_id.HasValue == false) { return(false); } crm.Contact crm_contact = Get_or_create_crm_contact(of_aftale.Contact_id.Value); bool update_nrq_bidragyder = false; if (crm_aftale.nrq_bidragyder == null || crm_aftale.nrq_bidragyder.Id != crm_contact.Id) { update_nrq_bidragyder = true; } crm_aftale.nrq_bidragyder = crm_contact.Get_entity_reference(); return(update_nrq_bidragyder); }
private void Update_aftale_in_crm(crm.Aftale crm_aftale, of.data.Agreement of_aftale) { List <string> parameters_to_update = Mapping.Aftale.Needs_update_in_crm(crm_aftale, of_aftale); if (parameters_to_update.Any() == false) { return; } Mapping.Aftale.To_crm(crm_aftale, of_aftale, _tracingService); bool update_nrq_bidragyder = Add_contact_to_aftale(crm_aftale, of_aftale); if (parameters_to_update.Contains("nrq_bidragyder") == false && update_nrq_bidragyder) { parameters_to_update.Add("nrq_bidragyder"); } Add_subscription_to_aftale(crm_aftale, of_aftale); crm_aftale.Update(parameters_to_update); }
protected override void Execute(CodeActivityContext codeActivityContext) { try { Initialize(codeActivityContext); int of_aftale_id = Of_aftale_id_InArgument.Get <int>(codeActivityContext); of.data.Agreement of_aftale = _of_connection.Agreement.Get(of_aftale_id); _tracingService.Trace($"of_id: {of_aftale_id}"); if (of_aftale == null) { return; } Maintain maintain = new Maintain(_service, _tracingService, _config, _of_connection); maintain.Create_or_update_one_aftale_in_crm(of_aftale); } catch (Exception exception) { Write_exception(exception); } }