예제 #1
0
        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}");
            }
        }
예제 #2
0
        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}");
            }
        }