Beispiel #1
0
        // fires off events, then does the actual delete
        public bool DeleteEntity(Entity entity)
        {
            bool bDeleteApproved = true;

            if (BeforeDelete != null)
            {
                foreach (BeforeDeleteHandler beforedeletecallback in BeforeDelete.GetInvocationList())
                {
                    if (!beforedeletecallback(this, new DeleteEntityEventArgs(entity)))
                    {
                        bDeleteApproved = false;
                    }
                }
            }

            if (!bDeleteApproved)
            {
                return(false);
            }

            if (ObjectDeleted != null)
            {
                ObjectDeleted(this, new ObjectDeletedArgs(DateTime.Now, entity.iReference, entity.GetType().ToString()));
            }
            entitybyreference.Remove(entity.iReference);
            entities.Remove(entity);

            if (AfterDelete != null)
            {
                AfterDelete(this, new DeleteEntityEventArgs(entity));
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Remove the value
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public async Task <ExecutionResult <T> > RemoveAsync(T value)
        {
            var connectMessage = Connect();

            if (connectMessage != "OK")
            {
                throw new ConnectionException(connectMessage);
            }

            BeforeDelete?.Invoke(value);

            var stop = new Stopwatch();

            stop.Start();

            if (_diagnosticSource.IsEnabled($"{typeof(T).Name}_Remove"))
            {
                _diagnosticSource.Write($"{typeof(T).Name}_Remove", value);
            }

            _logger.LogTrace("Try to remove item");

            T result = await TryRemove(value);

            stop.Stop();
            _logger.LogTrace($"End Remove in {stop.Elapsed}");

            AfterDelete?.Invoke(value);

            return(new ExecutionResult <T>(true, result));
        }
 protected virtual async Task <bool> OnBeforeDelete(GridDeleteComponent <T> component)
 {
     if (BeforeDelete != null)
     {
         return(await BeforeDelete.Invoke(component, _item));
     }
     return(true);
 }
Beispiel #4
0
 /// <summary>
 /// 删除c++中指针对应的对象.慎用
 /// </summary>
 public virtual void Release()
 {
     if (Handler != IntPtr.Zero)
     {
         BeforeDelete?.Invoke(this);
         WebrtcObject_delete(Handler);
         Handler = IntPtr.Zero;
     }
 }
Beispiel #5
0
        public async Task DeleteAsync(long id)
        {
            var entityEntry = _context.Entry(CreateInstance <T>());

            entityEntry.Property <long>(nameof(Entity.Id)).CurrentValue = id;
            entityEntry.State = EntityState.Deleted;
            BeforeDelete?.Invoke(ref entityEntry);
            await _context.SaveChangesAsync();
        }
Beispiel #6
0
        public virtual void DeleteRange(params TModel[] models)
        {
            var eArgs = new RepositoryEventArgs <TModel>();

            eArgs.Models = models;

            BeforeDelete?.Invoke(eArgs);

            dbSet.RemoveRange(models);
        }
Beispiel #7
0
        public bool Delete(object key)
        {
            LinkedListNode <KeyValuePair <object, object> > node;
            bool found = this.store.TryGetValue(key, out node);

            if (!found)
            {
                return(false);
            }
            this.store.Remove(key);
            BeforeDelete?.Invoke(node);
            this.list.Remove(node);
            return(true);
        }
Beispiel #8
0
        public bool Delete(object value)
        {
            LinkedListNode <object> node;
            bool found = this.store.TryGetValue(value, out node);

            if (!found)
            {
                return(false);
            }
            this.store.Remove(value);
            BeforeDelete?.Invoke(node);
            this.list.Remove(node);
            return(true);
        }
Beispiel #9
0
        public virtual void Delete(TModel model)
        {
            var eArgs = new RepositoryEventArgs <TModel>();

            eArgs.Model = model;

            BeforeDelete?.Invoke(eArgs);

            if (context.Entry(model).State == EntityState.Detached)
            {
                dbSet.Attach(model);
            }

            dbSet.Remove(model);
        }
Beispiel #10
0
 internal bool OnBeforeDelete(object sender, IDbEntity dbEntity)
 {
     return(BeforeDelete?.Invoke(sender, dbEntity) ?? true);
 }
 protected override void OnBeforeDelete(T entity)
 {
     BeforeDelete?.Invoke(entity);
     _validator?.ValidateAndThrowOnDelete(entity);
 }
Beispiel #12
0
 public void Delete()
 {
     Serializer.Delete(fileName, folderName, () => { BeforeDelete?.Invoke(); }, () => { AfterDelete?.Invoke(); });
 }
Beispiel #13
0
        public virtual TransactionResult Delete(T entity, string headerkeyvalue = null, bool useLog = true)
        {
            if (Context.Database.Connection.State != ConnectionState.Open)
            {
                Context.Database.Connection.Open();
            }

            TransactionScope scope = new TransactionScope();

            try
            {
                var keyvalue = entity.GetValue(MasterKey.IsNullOrEmpty() ? GetKeys[0] : MasterKey);
                var row      = Find(entity);
                entity = row; Context.Entry(entity).State = EntityState.Deleted;
                if (BeforeDelete != null)
                {
                    var eventUseData = new EventUseData();
                    BeforeDelete.Invoke(entity, Context, eventUseData);
                    if (eventUseData.Cancel)
                    {
                        scope.Dispose();
                        return(eventUseData.Message);
                    }
                }

                //if (_user.FollowUp && useLog)
                //{
                //    Context.LogEntity(entity, _user, GetKeys[0], _formType, headerkeyvalue, headerkeyvalue);
                //}
                Context.SaveChanges();

                //var lkpWebControllers = Context.lkp_WebControllers.FirstOrDefault(c => c.formType == _formType); //c.ControllerName.Equals(_controllername, StringComparison.OrdinalIgnoreCase) ||
                //if (lkpWebControllers != null)
                //{
                //    int formType = lkpWebControllers.formType;
                //    RemoveAttachments(formType, keyvalue.ToString());
                //}

                scope.Complete();
                if (AfterDelete != null)
                {
                    EventBase eventMessage = new EventBase {
                        Message = TransactionResult.None
                    };
                    AfterDelete.Invoke(entity, Context, eventMessage);
                    if (eventMessage.Message != TransactionResult.None)
                    {
                        return(eventMessage.Message);
                    }
                }
                return(TransactionResult.DeleteSuccess);
            }
            catch (Exception ex)
            {
                HandleException(ex);
                scope.Dispose();
                Context.Database.Connection.Close();
                //Logger.LogSystemError(_user.UserId.ToString(), ex);
                return(TransactionResult.DeleteFailed);
            }
            finally
            {
                scope.Dispose();
            }
        }
 protected virtual void OnBeforeDelete(T entity)
 {
     BeforeDelete?.Invoke(entity);
 }