private static void AddUIDToEntities(Course1C course, int acc_id, CatalogElement ce) { ce.custom_fields.Add(new CatalogElement.Custom_fields() { id = FieldLists.Courses[acc_id]["product_id_1C"], values = new CatalogElement.Custom_fields.Values[] { new CatalogElement.Custom_fields.Values() { value = course.product_id_1C.Value.ToString("D") } } }); }
private static void UpdateCourseInAmo(Course1C course, IAmoRepo <Lead> leadRepo, int ce_id, int acc_id) { CatalogElement ce = new() { id = ce_id, name = course.name, custom_fields = new() }; AddUIDToEntities(course, acc_id, ce); PopulateCFs(course, acc_id, ce); leadRepo.UpdateCEs(ce); }
private static void PopulateCFs(Course1C course, int acc_id, CatalogElement ce) { foreach (var p in course.GetType().GetProperties()) { if (FieldLists.Courses[acc_id].ContainsKey(p.Name) && p.GetValue(course) is not null) { if (p.Name == "price") { continue; } try { if ((string)p.GetValue(course) == "") { continue; } } catch { } ce.custom_fields.Add(new CatalogElement.Custom_fields() { id = FieldLists.Courses[acc_id][p.Name], values = new CatalogElement.Custom_fields.Values[] { new CatalogElement.Custom_fields.Values() { value = p.GetValue(course).ToString() } } }); } } if (course.ItemPrices is not null && course.ItemPrices.Any()) { ce.custom_fields.Add(new CatalogElement.Custom_fields() { id = FieldLists.Courses[acc_id]["price"], values = new CatalogElement.Custom_fields.Values[] { new CatalogElement.Custom_fields.Values() { value = course.ItemPrices.First().Price.ToString() } } }); } }
internal Guid UpdateCourse(Course1C course) { if (course.product_id_1C is null || course.product_id_1C == default) { throw new Exception("Unable to update 1C client, no UID."); } string method = "EditCourse"; string content = JsonConvert.SerializeObject(course, 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.product_id_1C); }
private static Amo_id CreateCourseInAmo(Course1C course, IAmoRepo <Lead> leadRepo, int acc_id) { CatalogElement ce = new() { name = course.name, custom_fields = new() }; AddUIDToEntity(course, acc_id, ce); PopulateCFs(course, acc_id, ce); var result = leadRepo.AddCEs(ce); if (!result.Any()) { throw new Exception($"Unable to update course in amo {course.name}"); } return(new() { account_id = acc_id, entity_id = result.First().id }); }
public UpdateAmoCourse(Course1C course, Amo amo, Log log) { _amo = amo; _log = log; _course1C = course; }
internal Course1C GetCourse(Course1C course) => GetCourse((Guid)course.product_id_1C);
public CreateOrUpdateAmoCourse(Course1C course1C, Amo amo, Log log) { _amo = amo; _log = log; _course1C = course1C; }