public string Create(string accountId, Ad model) { _results = new List <ValidationResult>(); _validationContext = new ValidationContext(model); var isValid = Validator.TryValidateObject(model, _validationContext, _results); ResponseShared response = null; if (!isValid) { throw new Exception("The Ads is invalid model, more inner exception", new Exception(GetErrorsMesages())); } accountId = GetAccount(accountId); //Valid Rules for Create Campaigns based in Facebook Api. if (model != null && !string.IsNullOrEmpty(accountId)) { try { response = ((string)_client.Post($"{accountId}/{ENDPOINT}", model)).JsonToObject <ResponseShared>(ResponseType.Other); if (response == null || string.IsNullOrEmpty(response.Id)) { throw new Exception("Error to trying saved Ads in Facebook"); } } catch (Exception e) { throw e; } } return(response.Id); }
public bool Update(string adsetId, AdSet adset) { _results = new List <ValidationResult>(); _validationContext = new ValidationContext(adset); var isValid = Validator.TryValidateObject(adset, _validationContext, _results); ResponseShared response = null; if (!isValid) { throw new Exception("The Campaign is invalid model, more inner exception", new Exception(GetErrorsMesages())); } //accountId = GetAccount(accountId); //Valid Rules for Create Campaigns based in Facebook Api. if (adset != null && !string.IsNullOrEmpty(adsetId)) { try { response = ((string)_client.Post($"{adsetId}/", adset)).JsonToObject <ResponseShared>(ResponseType.Other); if (response == null || !response.IsSuccess) { throw new Exception("Error to trying saved adset in Facebook"); } } catch (Exception e) { throw e; } } else { throw new Exception("The AdSet Id is empty"); } return(response.IsSuccess); }