public virtual async Task <TEntity> Handle(UpdateCommandModel <TEntity, TUpdate> command, CancellationToken cancellationToken)
        {
            _mapper.Map(command.Request, command.Entity);

            Repository.Edit(command.Entity);

            return(command.Entity);
        }
Ejemplo n.º 2
0
        public void UpdateCursor(int position)
        {
            var command = new UpdateCommandModel
            {
                Position = position,
            };

            socket.Send(JsonConvert.SerializeObject(command));
        }
        private ValidationResult Validate <T>(UpdateCommandModel <T> update, ValidationContext context)
        {
            if (update == null || !update.IsModified)
            {
                return(ValidationResult.Success);
            }

            var validation = Validation
                             .GetConstructor(new Type[] { })
                             .Invoke(new object[] { })
                             as ValidationAttribute;

            return(validation?.GetValidationResult(update.Value, context));
        }
Ejemplo n.º 4
0
        public Task <bool> Handle(UpdateCommandModel request, CancellationToken cancellationToken)
        {
            if (!request.VerifyData())
            {
                NotifyValidationErrors(request);
                return(Task.FromResult(false));
            }

            Infrastructure.Entitys.Permission entity = new Infrastructure.Entitys.Permission()
            {
                PermissionId       = request.PermissionId.ToString(),
                PermissionName     = request.PermissionName,
                PermissionAction   = request.PermissionAction,
                PermissionType     = request.PermissionType.EnumToInt(),
                PermissionParentId = request.PermissionParentId,
                IsValid            = request.IsValid
            };

            var existingEntity = _REPOSITORY.QueryByNameTypeParentId(entity.PermissionName, entity.PermissionType, entity.PermissionParentId);

            if (existingEntity != null && existingEntity.PermissionId != entity.PermissionId)
            {
                if (!existingEntity.Equals(entity))
                {
                    _Bus.RaiseEvent(new DomainNotification("Permission", "不存在该权限的信息!"), "Permission");
                    return(Task.FromResult(false));
                }
            }

            if (_REPOSITORY.UpdatePermission(entity))
            {
                _Bus.RaiseEvent(new Domain.Models.EventModels.Permission.UpdatePermissionEventModel(entity.PermissionId.StringToGuid(),
                                                                                                    entity.PermissionName,
                                                                                                    entity.PermissionType.IntToEnum <Models.CommandModels.Permission.PermissionCommandModel.PermissionTypeEnum>(),
                                                                                                    entity.PermissionAction,
                                                                                                    entity.PermissionParentId,
                                                                                                    entity.IsValid), "Permission");
                return(Task.FromResult(true));
            }
            else
            {
                _Bus.RaiseEvent(new DomainNotification("Permission", "修改权限失败!"), "Permission");
                return(Task.FromResult(false));
            }
        }