/// <summary> /// Performs removing of requested records. /// </summary> /// <param name="request">Request holding store changes.</param> /// <param name="response">Response to put updating results into.</param> /// <returns>Response object.</returns> public SyncStoreResponse HandleRemoved(SyncStoreRequest <T> request, SyncStoreResponse response) { IList <IDictionary <String, Object> > removed = new List <IDictionary <String, Object> >(); SyncStoreResponse resp = response ?? new SyncStoreResponse(); if (request.removed != null) { foreach (T row in request.removed) { removed.Add(OnRecordRemoved(row, Remove(row))); } } if (removed.Count > 0) { if (resp.removed != null) { resp.removed = resp.removed.Concat(removed).ToList(); } else { resp.removed = removed; } } return(OnRemovedHandled(resp)); }
/// <summary> /// Applies changes passed in a sync request to the store. /// </summary> /// <param name="request">A sync request.</param> /// <returns>Response object for the applied changes.</returns> public SyncStoreResponse Handle(SyncStoreRequest <T> request, Rows mode = Rows.All) { SyncStoreResponse res = new SyncStoreResponse(); if (mode == Rows.All || mode == Rows.Added || mode == Rows.AddedAndUpdated) { HandleAdded(request, res); } if (mode == Rows.All || mode == Rows.Updated || mode == Rows.AddedAndUpdated) { HandleUpdated(request, res); } if (mode == Rows.All || mode == Rows.Removed) { HandleRemoved(request, res); } if (mode == Rows.All) { bool hasRows = res.rows != null && res.rows.Count > 0; bool hasRemoved = res.removed != null && res.removed.Count > 0; if (!hasRows && !hasRemoved) { throw new CrudException("No data to save.", Codes.NO_SYNC_DATA); } } return(OnHandled(res)); }
/// <summary> /// Performs updating of requested records. /// </summary> /// <param name="request">Request holding store changes.</param> /// <param name="response">Response to put updating results into.</param> /// <returns>Response object.</returns> public SyncStoreResponse HandleUpdated(SyncStoreRequest <T> request, SyncStoreResponse response) { IList <IDictionary <String, Object> > updated = new List <IDictionary <String, Object> >(); SyncStoreResponse resp = response ?? new SyncStoreResponse(); if (request.updated != null) { foreach (IDictionary <String, Object> changes in request.updated) { T record = GetEntity(changes); updated.Add(OnRecordUpdated(record, Update(record, changes))); } } if (updated.Count > 0) { if (resp.rows != null) { resp.rows = resp.rows.Concat(updated).ToList(); } else { resp.rows = updated; } } return(OnUpdatedHandled(resp)); }