Exemple #1
0
        private CUDResult UpsertChecks(CUDResult opResult, BookmarkDto dto)
        {
            // If we are checking an insert operation
            if (dto.Id == 0)
            {
                if (Get_ForUrl(dto.Url) != null)
                {
                    opResult.Errors.Add($"A bookmark with this url already exists.");
                }
            }
            // If we are checking an update operation
            {
                // Look for bookmarks with this url that are not this record
                var dupeResults = Find(s =>
                                       s.Id != dto.Id &&
                                       s.Url.Equals(dto.Url, StringComparison.Ordinal) // Note: case 'sensitive' compare so we allow renames to upper/lower case
                                       );

                if (dupeResults.Any())
                {
                    opResult.Errors.Add($"A bookmark with this url already exists.");
                    return(opResult);
                }
            }

            return(opResult);
        }
Exemple #2
0
        public override CUDResult Delete(int deletingId)
        {
            var opResult = new CUDResult();

            opResult = base.Delete(deletingId);
            UpdateTags();
            return(opResult);
        }
Exemple #3
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);
        }
Exemple #4
0
        public override CUDResult Update(BookmarkDto updatingObject)
        {
            var opResult = new CUDResult();

            opResult = UpsertChecks(opResult, updatingObject);
            if (opResult.Errors.Any())
            {
                return(opResult);
            }

            opResult = base.Update(updatingObject);
            UpdateTags();
            return(opResult);
        }
Exemple #5
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);
        }
Exemple #6
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);
        }