Exemple #1
0
        protected override void OnRemove(IRemoveEntityParams removeEntityParams, TEntity entity)
        {
            var culturedEntity = CulturedEntities.FirstOrDefault(x =>
                                                                 x.BaseEntityId == entity.Id && x.Culture == removeEntityParams.Culture);

            if (culturedEntity != null)
            {
                culturedEntity.CulturedEntityStatus = Status.Removed;
                _applicationDbContext.SaveChanges();

                var hasStatusEntity = entity as IHasStatus;

                if (hasStatusEntity != null)
                {
                    var isAllCulturedEntitiesRemoved = CulturedEntities.All(x =>
                                                                            x.BaseEntityId == entity.Id && x.CulturedEntityStatus == Status.Removed);

                    if (isAllCulturedEntitiesRemoved)
                    {
                        hasStatusEntity.Status = Status.Removed;

                        _applicationDbContext.Update(entity);
                        _applicationDbContext.SaveChanges();
                    }
                }
            }
        }
Exemple #2
0
        public RemoveResultStatus RemoveCulturedEntity(IRemoveEntityParams removeEntityParams)
        {
            var culturedEntity = CulturedEntityGet(removeEntityParams.Id);

            if (culturedEntity == null)
            {
                return(RemoveResultStatus.Success);
            }

            if (culturedEntity is DateOperationFields)
            {
                var operatorFields = culturedEntity as DateOperationFields;

                operatorFields.AssignOperatorFields(OperationType.Remove);
            }

            var hasStatusCulturedEntity = culturedEntity as IHasStatus;

            if (hasStatusCulturedEntity != null && removeEntityParams.CheckRelationalEntities)
            {
                foreach (var propertyInfo in culturedEntity.GetType().GetProperties().Where(p =>
                                                                                            p.PropertyType.IsGenericType && p.PropertyType
                                                                                            .GetGenericTypeDefinition() == typeof(ICollection <>)))
                {
                    var value            = propertyInfo.GetValue(culturedEntity, null);
                    var hasStatusRecords = value as IEnumerable <IHasStatus>;

                    if (hasStatusRecords == null)
                    {
                        if (((IEnumerable <IEntity>)value).Any())
                        {
                            return(RemoveResultStatus.HasRelatedEntities);
                        }
                    }
                    else
                    {
                        if (hasStatusRecords.Count(x => x.Status != Status.Removed) > 0)
                        {
                            return(RemoveResultStatus.HasRelatedEntities);
                        }
                    }
                }
            }
            if (hasStatusCulturedEntity != null && !removeEntityParams.RemovePermanently)
            {
                if (hasStatusCulturedEntity.Status == Status.Removed)
                {
                    return(RemoveResultStatus.Success);
                }

                hasStatusCulturedEntity.Status = Status.Removed;

                _applicationDbContext.Update(culturedEntity);
            }
            else
            {
                _applicationDbContext.Remove(culturedEntity);
            }

            _applicationDbContext.SaveChanges();



            var entity = Get(culturedEntity.BaseEntityId);

            culturedEntity.CulturedEntityStatus = Status.Removed;
            _applicationDbContext.SaveChanges();

            var hasStatusEntity = entity as IHasStatus;

            if (hasStatusEntity != null)
            {
                var isAllCulturedEntitiesRemoved = CulturedEntities.All(x =>
                                                                        x.BaseEntityId == entity.Id && x.CulturedEntityStatus == Status.Removed);

                if (isAllCulturedEntitiesRemoved)
                {
                    hasStatusEntity.Status = Status.Removed;

                    _applicationDbContext.Update(entity);
                    _applicationDbContext.SaveChanges();
                }
            }
            OnCulturedEntityRemoved(culturedEntity.Id);

            return(RemoveResultStatus.Success);
        }
Exemple #3
0
 protected virtual void OnRemoved(IRemoveEntityParams removeEntityParams, TEntity entity)
 {
 }