コード例 #1
0
        public virtual CUDResult Delete(int deletingId)
        {
            var opResult = new CUDResult();

            if (CUDDepthTracking.ExceedsMaxOperationDepth(opResult))
            {
                return(opResult);
            }

            var dtoBefore = Get(deletingId);

            try
            {
                CUDDepthTracking.OperationDepth++;
                OnBeforeRecordDeleted?.Invoke(
                    new DataProviderRecordDeletedEventArgs()
                {
                    DtoBefore = dtoBefore,
                });
            }
            catch (Exception ex)
            {
                opResult.Errors.Add(ex.ToString());
            }
            finally
            {
                CUDDepthTracking.OperationDepth--;
            }

            if (!collection.Delete(deletingId))
            {
                opResult.Errors.Add($"{CollectionName} with id {deletingId} was not found to delete.");
            }

            try
            {
                CUDDepthTracking.OperationDepth++;
                OnAfterRecordDeleted?.Invoke(
                    new DataProviderRecordDeletedEventArgs()
                {
                    DtoBefore = dtoBefore,
                });
            }
            catch (Exception ex)
            {
                opResult.Errors.Add(ex.ToString());
            }
            finally
            {
                CUDDepthTracking.OperationDepth--;
            }

            return(opResult);
        }
コード例 #2
0
        public virtual CUDResult Update(T updatingObject)
        {
            var opResult = new CUDResult();

            if (CUDDepthTracking.ExceedsMaxOperationDepth(opResult))
            {
                return(opResult);
            }

            var updateEvent = new DataProviderRecordUpdatedEventArgs()
            {
                DtoBefore = Get(updatingObject.Id),
                DtoAfter  = updatingObject,
            };

            if (collection.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);
        }
コード例 #3
0
        public virtual CUDResult Insert(T insertingObject)
        {
            var opResult = new CUDResult();

            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);
            }

            collection.Insert(insertingObject);

            try
            {
                CUDDepthTracking.OperationDepth++;
                OnRecordCreated?.Invoke(
                    new DataProviderRecordCreatedEventArgs()
                {
                    CreatedDto = insertingObject
                });
            }
            catch (Exception ex)
            {
                opResult.Errors.Add(ex.ToString());
            }
            finally
            {
                CUDDepthTracking.OperationDepth--;
            }
            return(opResult);
        }