コード例 #1
0
        public void Before(Services.tmp.EntityOperation operation, EntityOperationContext context)
        {
            if (operation.IsEntity(Payment.ENTITY) && operation is EntityUpdate)
            {
                var update = operation as EntityUpdate;
                if (update.IsCreate())
                {
                    List <int> usersToAttach = new List <int>();
                    foreach (var attach in update.RelationUpdates.Where(ru => ru.Operation == Services.tmp.RelationOperation.Attach))
                    {
                        var em          = _domainService.Domain.Entities[attach.Entity];
                        var customerRel = em.Relations[em.Name, User.ENTITY, Payment.ROLE_CUSTOMER];
                        if (customerRel != null && customerRel.TypeFor(User.ENTITY) == RelationType.OneToMany)
                        {
                            var q = new EntityQuery2(User.ENTITY);
                            q.WhereRelated(new RelationQuery(em.Name, customerRel.Role, attach.Id.Value));
                            var cust = _repository.Read(q);
                            if (cust != null)
                            {
                                usersToAttach.Add(cust.Id);
                            }
                        }
                    }

                    foreach (var id in usersToAttach)
                    {
                        update.Attach(User.ENTITY, Payment.ROLE_CUSTOMER, id);
                    }
                }
            }
        }
コード例 #2
0
 public void Before(Services.tmp.EntityOperation operation, EntityOperationContext context)
 {
     if (operation is EntityUpdate)
     {
         var update = operation as EntityUpdate;
         if (update.IsCreate())
         {
             update.Set(Properties.CreatedBy, _securityService.CurrentUser.Id);
             update.Set(Properties.CreatedOn, DateTime.Now);
         }
     }
 }
コード例 #3
0
ファイル: FilesModule.cs プロジェクト: jeason0813/NbuLibrary
 public void After(Services.tmp.EntityOperation operation, EntityOperationContext context, EntityOperationResult result)
 {
     if (operation.IsEntity(NbuLibrary.Core.Domain.File.ENTITY) &&
         operation is EntityDelete &&
         result.Success)
     {
         var file = context.Get <NbuLibrary.Core.Domain.File>(CTXKEY_FILEDELETION);
         if (file != null)
         {
             _fileService.DeleteFileContent(Guid.Parse(file.ContentPath));
         }
     }
 }
コード例 #4
0
 InspectionResult IEntityOperationInspector.Inspect(Services.tmp.EntityOperation operation)
 {
     if (CurrentUser == null)
     {
         return(InspectionResult.Deny);
     }
     else if (CurrentUser.UserType == UserTypes.Admin)
     {
         return(InspectionResult.Allow);
     }
     else
     {
         return(InspectionResult.None);
     }
 }
コード例 #5
0
 public InspectionResult Inspect(Services.tmp.EntityOperation operation)
 {
     if (operation.IsEntity(Payment.ENTITY) && operation is EntityUpdate)
     {
         var update = operation as EntityUpdate;
         if (update.IsCreate() && !update.ContainsProperty("Status"))
         {
             return(InspectionResult.Allow); //TODO-Finance: Everyone is allowed to create payments
         }
         else if (_securityService.HasModulePermission(_securityService.CurrentUser, FinanceModule.Id, Permissions.Approve))
         {
             return(InspectionResult.Allow);
         }
     }
     return(InspectionResult.None);
 }
コード例 #6
0
        public void After(Services.tmp.EntityOperation operation, EntityOperationContext context, EntityOperationResult result)
        {
            if (!result.Success)
            {
                return;
            }

            using (var dbContext = _dbService.GetDatabaseContext(true))
            {
                if (operation is EntityDelete)
                {
                    LogOperation(operation.Entity, operation.Id.Value, HistoryOperation.Deleted, DateTime.Now, dbContext.Connection);
                }
                else if (operation is EntityUpdate)
                {
                    var  update  = operation as EntityUpdate;
                    bool created = result.Data.ContainsKey("Created");
                    var  now     = DateTime.Now;
                    int  opId    = LogOperation(update.Entity, update.Id.Value, created ? HistoryOperation.Created : HistoryOperation.Modified, now, dbContext.Connection);
                    foreach (var propUpdate in update.PropertyUpdates)
                    {
                        LogPropertyChange(opId, propUpdate.Key, propUpdate.Value, dbContext.Connection);
                    }

                    foreach (var relUpdate in update.RelationUpdates)
                    {
                        int relChangeId = LogRelationChange(opId, relUpdate.Entity, relUpdate.Role, relUpdate.Id.Value, relUpdate.Operation, dbContext.Connection);
                        foreach (var propUpdate in relUpdate.PropertyUpdates)
                        {
                            LogRelationPropertyChange(relChangeId, propUpdate.Key, propUpdate.Value, dbContext.Connection);
                        }
                    }
                }

                dbContext.Complete();
            }
        }
コード例 #7
0
ファイル: FilesModule.cs プロジェクト: jeason0813/NbuLibrary
        public void Before(Services.tmp.EntityOperation operation, EntityOperationContext context)
        {
            if (operation.IsEntity(NbuLibrary.Core.Domain.File.ENTITY) && operation is EntityUpdate)
            {
                var update = operation as EntityUpdate;
                if (update.IsCreate())
                {
                    var access = update.Attach(NbuLibrary.Core.Domain.User.ENTITY, Roles.Access, _securityService.CurrentUser.Id);
                    access.Set("Type", FileAccessType.Owner);
                }
                else
                {
                    var accessUpdates = update.GetMultipleRelationUpdates(User.ENTITY, Roles.Access);
                    if (accessUpdates != null)
                    {
                        foreach (var ac in accessUpdates)
                        {
                            if (ac.Operation == RelationOperation.Detach)
                            {
                                continue;
                            }

                            if (ac.ContainsProperty("Type") && ac.Get <FileAccessType>("Type") == FileAccessType.Token)
                            {
                                ac.Set("Token", Guid.NewGuid());//TODO: token based file access
                            }
                        }
                    }
                }
            }
            else if (operation.IsEntity(NbuLibrary.Core.Domain.File.ENTITY) && operation is EntityDelete)
            {
                var file = _fileService.GetFile(operation.Id.Value);
                context.Set <NbuLibrary.Core.Domain.File>(CTXKEY_FILEDELETION, file);
            }
        }
コード例 #8
0
 public void After(Services.tmp.EntityOperation operation, EntityOperationContext context, EntityOperationResult result)
 {
 }