private static void PopulateCFs(Lead1C lead1C, int acc_id, Lead lead) { foreach (var p in lead1C.GetType().GetProperties()) { if (FieldLists.Leads[acc_id].ContainsKey(p.Name) && p.GetValue(lead1C) is not null) { try { if ((string)p.GetValue(lead1C) == "") { continue; } } catch { } lead.custom_fields_values.Add(new Custom_fields_value() { field_id = FieldLists.Leads[acc_id][p.Name], values = new Custom_fields_value.Values[] { new Custom_fields_value.Values() { value = p.GetValue(lead1C) } } }); } } }
private static void UpdateLeadInAmo(Lead1C lead1C, IAmoRepo <Lead> leadRepo, int lead_id, int acc_id, RecentlyUpdatedEntityFilter filter) { Lead lead = new() { id = lead_id, price = lead1C.price, responsible_user_id = UserList.GetAmoUser(lead1C.responsible_user), custom_fields_values = new(), }; if (lead.responsible_user_id is null) { lead.responsible_user_id = UserList.GetAmoUser(lead1C.author); } AddUIDToEntity(lead1C, acc_id, lead); PopulateCFs(lead1C, acc_id, lead); try { filter.AddEntity(lead_id); leadRepo.Save(lead); } catch (Exception e) { throw new Exception($"Unable to update lead {lead_id} in amo: {e.Message}"); } }
public UpdateAmoLead(Lead1C lead1C, Amo amo, Log log, RecentlyUpdatedEntityFilter filter) { _amo = amo; _log = log; _lead1C = lead1C; _filter = filter; }
private static void UpdateLeadIn1C(Amo amo, Log log, Lead lead, Guid lead_id_1C, int amo_acc, Cred1C cred1C) { var repo1C = new LeadRepository(cred1C); Lead1C lead1C = repo1C.GetLead(lead_id_1C); if (lead1C == default) { throw new Exception($"Unable to update lead in 1C. 1C returned no lead {lead_id_1C}."); } PopulateCFs(lead, amo_acc, lead1C); lead1C.responsible_user = UserList.Get1CUser(lead.responsible_user_id); if (string.IsNullOrEmpty(lead1C.lead_status)) { lead1C.lead_status = "ВРаботе"; } if (amo_acc == 19453687) { lead1C.is_corporate = true; } repo1C.UpdateLead(lead1C); }
public CreateOrUpdateAmoLead(Lead1C lead1C, Amo amo, Log log, Cred1C cred1C, RecentlyUpdatedEntityFilter filter) { _amo = amo; _log = log; _lead1C = lead1C; _cred1C = cred1C; _filter = filter; }
private static void AddUIDToEntity(Lead1C lead1C, int acc_id, Lead lead) { lead.custom_fields_values.Add(new Custom_fields_value() { field_id = FieldLists.Leads[acc_id]["lead_id_1C"], values = new Custom_fields_value.Values[] { new Custom_fields_value.Values() { value = lead1C.lead_id_1C.Value.ToString("D") } } }); }
private static int CreateLeadInAmo(Lead1C lead1C, IAmoRepo <Lead> leadRepo, int acc_id, int contact_id, int course_id, int company_id, RecentlyUpdatedEntityFilter filter) { Lead lead = new() { name = "Новая сделка", price = lead1C.price, responsible_user_id = UserList.GetAmoUser(lead1C.responsible_user), custom_fields_values = new(), _embedded = new() { tags = new() { new() { name = "1C" } } } }; if (lead.responsible_user_id is null) { lead.responsible_user_id = UserList.GetAmoUser(lead1C.author); } AddUIDToEntity(lead1C, acc_id, lead); PopulateCFs(lead1C, acc_id, lead); PopulateConnectedEntities(contact_id, company_id, lead); try { var result = leadRepo.AddNewComplex(lead).ToList(); result.ForEach(x => filter.AddEntity(x)); if (result.Any()) { EntityLink link = new() { to_entity_id = course_id, to_entity_type = "catalog_elements", metadata = new() { quantity = 1, catalog_id = GetCatalogId(acc_id) } }; leadRepo.LinkEntity(result.First(), link); return(result.First()); } else { throw new Exception("Amo returned no lead Ids."); } } catch (Exception e) { throw new Exception($"Unable to update lead {lead1C.lead_id_1C} in amo: {e.Message}"); } }
internal Guid UpdateLead(Lead1C lead) { if (lead.lead_id_1C is null || lead.lead_id_1C == default) { throw new Exception("Unable to update 1C lead, no UID."); } string method = "EditApplication"; string content = JsonConvert.SerializeObject(lead, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Include });; Request1C request = new("POST", method, content, _cred1C); Result result = new(); var response = request.GetResponse(); try { JsonConvert.PopulateObject(WebUtility.UrlDecode(response), result); } catch (Exception e) { throw new Exception($"Unable to process response from 1C: {e.Message}, Response: {response}"); } return(result.lead_id_1C); }
private static void PopulateCFs(Lead lead, int amo_acc, Lead1C lead1C) { if (lead.custom_fields_values is not null) { foreach (var p in lead1C.GetType().GetProperties()) { if (FieldLists.Leads[amo_acc].ContainsKey(p.Name) && lead.custom_fields_values.Any(x => x.field_id == FieldLists.Leads[amo_acc][p.Name])) { var value = lead.custom_fields_values.First(x => x.field_id == FieldLists.Leads[amo_acc][p.Name]).values[0].value; if ((p.PropertyType == typeof(Guid?) || p.PropertyType == typeof(Guid)) && Guid.TryParse((string)value, out Guid guidValue)) { p.SetValue(lead1C, guidValue); continue; } p.SetValue(lead1C, value); } } } }
private static Guid GetOrCreateContragent(Amo amo, Lead1C lead1C, Cred1C cred1C, int amo_acc, RecentlyUpdatedEntityFilter filter) { if (amo_acc == 19453687) { return(default);
internal Lead1C GetLead(Lead1C lead) => GetLead((Guid)lead.lead_id_1C);