protected override CategoryFascicle BeforeDelete(CategoryFascicle entity, CategoryFascicle entityTransformed)
        {
            if (CurrentDeleteActionType != Common.Infrastructures.DeleteActionType.DeleteCategoryFascicle)
            {
                throw new DSWException(EXCEPTION_MESSAGE, null, DSWExceptionCode.SS_NotAllowedOperation);
            }

            if (entityTransformed.FascicleType == FascicleType.Procedure)
            {
                ICollection <CategoryFascicleTableValuedModel> subCategoryFascicles = _unitOfWork.Repository <CategoryFascicle>().GetCategorySubFascicles(entityTransformed.Category.EntityShortId);
                CategoryFascicle categoryFascicle;
                foreach (CategoryFascicleTableValuedModel toDelete in subCategoryFascicles)
                {
                    categoryFascicle = _unitOfWork.Repository <CategoryFascicle>().FindIncludeRights(toDelete.IdCategoryFascicle).Single();
                    _unitOfWork.Repository <CategoryFascicleRight>().DeleteRange(categoryFascicle.CategoryFascicleRights.ToList());
                    _unitOfWork.Repository <CategoryFascicle>().Delete(categoryFascicle);
                }

                ICollection <CategoryFascicle> periodicCategoryFascicleReferences = _unitOfWork.Repository <CategoryFascicle>().GetAllPeriodicByCategory(entityTransformed.Category.EntityShortId).ToList();
                CategoryFascicleRight          specialRight;
                foreach (CategoryFascicle periodicCategoryFascicleReference in periodicCategoryFascicleReferences)
                {
                    _unitOfWork.Repository <CategoryFascicleRight>().DeleteRange(periodicCategoryFascicleReference.CategoryFascicleRights.ToList());
                    if (_parameterEnvService.FascicleContainerEnabled)
                    {
                        specialRight = new CategoryFascicleRight()
                        {
                            CategoryFascicle = periodicCategoryFascicleReference,
                            Role             = _unitOfWork.Repository <Role>().GetByUniqueId(Guid.Empty).Single()
                        };
                        _unitOfWork.Repository <CategoryFascicleRight>().Insert(specialRight);
                    }
                }
            }

            if (entityTransformed.CategoryFascicleRights != null && entityTransformed.CategoryFascicleRights.Count > 0)
            {
                _unitOfWork.Repository <CategoryFascicleRight>().DeleteRange(entityTransformed.CategoryFascicleRights.ToList());
            }

            TableLog tableLog = TableLogService.CreateLog(entity.UniqueId, null, TableLogEvent.DELETE, $"Eliminato piano di fascicolazione di tipo {entityTransformed.FascicleType.ToString()} con environment {entityTransformed.DSWEnvironment}", nameof(CategoryFascicle), CurrentDomainUser.Account);

            _unitOfWork.Repository <TableLog>().Insert(tableLog);

            return(base.BeforeDelete(entity, entityTransformed));
        }
Example #2
0
 protected override PrivacyLevel BeforeUpdate(PrivacyLevel entity, PrivacyLevel entityTransformed)
 {
     _unitOfWork.Repository <TableLog>().Insert(TableLogService.CreateLog(entityTransformed.UniqueId, null, TableLogEvent.PRIVACY, string.Format("Modifica livello di privacy con livello {0}, attivo {1}", entityTransformed.Level, entityTransformed.IsActive), typeof(PrivacyLevel).Name, CurrentDomainUser.Account));
     return(base.BeforeUpdate(entity, entityTransformed));
 }