public ZohoInsertResponse InsertRecords <T>(IEnumerable <T> records) where T : ZohoEntity { AssertTypeIsNotAbstract(typeof(T)); AssertAllowInserts(typeof(T)); AssertAllowMultipleInserts(typeof(T), records); ZohoEntityCollection <T> collection; if (records is ZohoEntityCollection <T> ) { collection = (ZohoEntityCollection <T>)records; } else { collection = new ZohoEntityCollection <T>(); foreach (var record in records) { collection.Add(record); } } var moduleName = ModuleName(typeof(T)); var xmlData = collection.ToXmlString(); return(PostData(moduleName, "insertRecords", null, xmlData)); }
public void InsertTwiceTheSameRecordAtTheSameTime() { var client = CreateClient(); var records = new ZohoEntityCollection <T> { CreateEntry(0), CreateEntry(0) }; var response = client.InsertRecords(records); }
internal ZohoEntityCollection <T> LoadCollectionFromResul <T>() where T : ZohoEntity { var collection = new ZohoEntityCollection <T>(true); if (!NoData) { var firstNode = resultNode.Elements().First(); collection.LoadFromXml(firstNode); } return(collection); }
public void InsertMultipleRecords() { var client = CreateClient(); var entries = new ZohoEntityCollection <T>(); for (int i = 0; i < 3; i++) { entries.Add(CreateEntry(i)); } var response = client.InsertRecords(entries); Assert.AreEqual(3, response.RecordDetails.Count()); foreach (var detail in response.RecordDetails) { Console.Out.WriteLine("(ID = {0}) Created On {1} by {2}", detail.Id, detail.CreatedDate, detail.CreatedBy); } }
public bool UpdateRecord <T>(string id, T record) where T : ZohoEntity { AssertTypeIsNotAbstract(typeof(T)); AssertAllowInserts(typeof(T)); var collection = new ZohoEntityCollection <T> { record }; var moduleName = ModuleName(typeof(T)); var xmlData = collection.ToXmlString(); var response = PostData(moduleName, "updateRecords", new Dictionary <string, string> { { "id", id } }, xmlData); if (response.RecordDetails.Count() != 1) { throw new InvalidOperationException("Invalid number of details returned"); } var detail = response.RecordDetails.First(); return(detail.Id == id); }
public ZohoBulkUpsertRepsonse <T> BulkUpsertRecords <T>(IList <T> records) where T : ZohoEntity { AssertTypeIsNotAbstract(typeof(T)); AssertAllowInserts(typeof(T)); AssertAllowMultipleInserts(typeof(T), records); var collection = new ZohoEntityCollection <T>(); foreach (var record in records) { collection.Add(record); } var moduleName = ModuleName(records.FirstOrDefault()); var xmlData = collection.ToXmlString(); this.DuplicateCheck = InsertDuplicateCheck.Update; var rawHtmlRepsonse = PostDataRaw(moduleName, "insertRecords", null, xmlData, 4, true); var response = new ZohoBulkUpsertRepsonse <T>(rawHtmlRepsonse, requestItems: records.ToList()); return(response); }