private static Dictionary <string, Record> GetMap(RecordSet recordSet) { var map = new Dictionary <string, Record>(); foreach (var record in recordSet) { string id = GetId(record); if (id != null) { map.Add(id, record); } } return(map); }
internal ApiUpdate(Api api, EntitySchema entity, RecordSet records, ApiUpdateMode mode) { if (api == null) { throw new ArgumentNullException(nameof(api)); } if (entity == null) { throw new ArgumentNullException(nameof(entity)); } _api = api; Entity = entity; Mode = mode; Records = records ?? new RecordSet(); }
public static RecordSetChanges Create(RecordSet original, RecordSet modified) { if (original == null) { throw new ArgumentNullException(nameof(original)); } if (modified == null) { throw new ArgumentNullException(nameof(modified)); } var originalMap = GetMap(original); var modifiedMap = GetMap(modified); var deleted = originalMap.Keys.Where(p => !modifiedMap.ContainsKey(p)).ToList(); var newRecords = new List <Record>(); var modifiedRecords = new List <Record>(); foreach (var modifiedRecord in modified) { string id = GetId(modifiedRecord); Record originalRecord; if (id != null && originalMap.TryGetValue(id, out originalRecord)) { if (!AreEqual(originalRecord, modifiedRecord)) { modifiedRecords.Add(modifiedRecord); } } else { newRecords.Add(modifiedRecord); } } return(new RecordSetChanges(new RecordSet(newRecords), new RecordSet(modifiedRecords), deleted)); }
public ApiUpdate CreateUpdate(EntitySchema entity, RecordSet records) { return(new ApiUpdate(this, entity, records, ApiUpdateMode.Update)); }
private RecordSetChanges(RecordSet @new, RecordSet modified, IList <string> deleted) { New = @new; Modified = modified; Deleted = deleted; }