/// <summary> /// A universal method for adding an object passed in an instance of a class /// </summary> /// <param name="obj">The structure of the added object</param> /// <param name="url">URL request</param> /// <param name="cookies">Cookies container</param> /// <exception cref="AmoCrmException">Return error from server</exception> /// <returns>Deserialize the response to the specified class</returns> public async Task <T> AddObjAsync <T>(AddOrUpdateCommand <T> obj, string url, CookieContainer cookies) where T : class { var response = await Requests.PostAsync <Result>(url, JsonConvert.SerializeObject(obj), cookies); if (!response.Success) { throw new ArgumentException(response.ErrorCode + ":" + response.ErrorMessage); } return(response.Content.DeserializeTo <T>()); }
/// <summary> /// Method for adding a company /// </summary> /// <param name="company">The structure of the added company</param> /// <exception cref="AmoCrmException">Return error from server</exception> /// <returns>Deserialize the response to the specified class</returns> public async Task <T> AddCompanyAsync <T>(AddOrUpdateCommand <AmoCrmCompany> company) where T : class { var response = await Requests.PostAsync <Result>(_crmConfig.CompanyUrl, JsonConvert.SerializeObject(company), _crmConfig); if (!response.Success) { throw new ArgumentException(response.ErrorCode + ":" + response.ErrorMessage); } return(response.Content.DeserializeTo <T>()); }
/// <summary> /// Method for adding a lead /// </summary> /// <param name="leads">The structure of the added lead</param> /// <param name="url">URL request</param> /// <param name="credential">Used By: UserName, Password, Domain</param> /// <exception cref="AmoCrmException">Return error from server</exception> /// <returns>Deserialize the response to the specified class</returns> public async Task <T> AddLeadAsync <T>(AddOrUpdateCommand <AmoCrmLead> leads, string url, NetworkCredential credential) where T : class { var response = await Requests.PostAsync <Result>(url, JsonConvert.SerializeObject(leads), credential); if (!response.Success) { throw new ArgumentException(response.ErrorCode + ":" + response.ErrorMessage); } return(response.Content.DeserializeTo <T>()); }