public virtual CMCUDResult Delete(int deletingId) { var opResult = new CMCUDResult(); if (CUDDepthTracking.ExceedsMaxOperationDepth(opResult)) { return(opResult); } var dtoBefore = Get(deletingId); try { CUDDepthTracking.OperationDepth++; OnBeforeRecordDeleted?.Invoke( new CMDataProviderRecordDeletedEventArgs() { DtoBefore = dtoBefore, }); } catch (Exception ex) { opResult.Errors.Add(ex.ToString()); } finally { CUDDepthTracking.OperationDepth--; } if (!cmCollection.Delete(deletingId)) { opResult.Errors.Add($"{CollectionName} with id {deletingId} was not found to delete."); } try { CUDDepthTracking.OperationDepth++; OnAfterRecordDeleted?.Invoke( new CMDataProviderRecordDeletedEventArgs() { DtoBefore = dtoBefore, }); } catch (Exception ex) { opResult.Errors.Add(ex.ToString()); } finally { CUDDepthTracking.OperationDepth--; } return(opResult); }
public virtual CMCUDResult Update(T updatingObject) { var opResult = new CMCUDResult(); if (CUDDepthTracking.ExceedsMaxOperationDepth(opResult)) { return(opResult); } var updateEvent = new CMDataProviderRecordUpdatedEventArgs() { DtoBefore = Get(updatingObject.Id), DtoAfter = updatingObject, }; if (cmCollection.Update(updatingObject) == false) { opResult.Errors.Add($"An item in {CollectionName} with id {updatingObject.Id} was not found to update."); return(opResult); } try { CUDDepthTracking.OperationDepth++; OnRecordUpdated?.Invoke(updateEvent); } catch (Exception ex) { opResult.Errors.Add(ex.ToString()); } finally { CUDDepthTracking.OperationDepth--; } return(opResult); }
public virtual CMCUDResult Insert(T insertingObject) { var opResult = new CMCUDResult(); if (CUDDepthTracking.ExceedsMaxOperationDepth(opResult)) { return(opResult); } if (insertingObject.Id != 0) { opResult.Errors.Add($"Cannot insert a new item into {CollectionName}. New items must have their id set to 0 before insert."); return(opResult); } cmCollection.Insert(insertingObject); try { CUDDepthTracking.OperationDepth++; OnRecordCreated?.Invoke( new CMDataProviderRecordCreatedEventArgs() { CreatedDto = insertingObject }); } catch (Exception ex) { opResult.Errors.Add(ex.ToString()); } finally { CUDDepthTracking.OperationDepth--; } return(opResult); }