private void HandleCreateMethod(CreateMethod createMethod)
        {
            Result <Method> methodCreationResult = _repository.CreateMethod(createMethod);

            if (methodCreationResult.IsFailure)
            {
                MethodCreationFailed failedMethod =
                    new MethodCreationFailed(
                        methodCreationResult.Error,
                        createMethod.LoggedInUserId,
                        createMethod.SagaId
                        );
                _kafkaProducer.Produce(failedMethod, METHODS_TOPIC);
                return;
            }

            MethodCreated createdMethod = new MethodCreated(
                methodCreationResult.Value.Id,
                methodCreationResult.Value.Creator,
                methodCreationResult.Value.Name,
                methodCreationResult.Value.ApplicationRate,
                methodCreationResult.Value.CreationDate,
                createMethod.LoggedInUserId,
                createMethod.SagaId
                );

            _kafkaProducer.Produce(createdMethod, METHODS_TOPIC);
        }
Example #2
0
        private async void HandleMethodCreated(MethodCreated m)
        {
            if (m.SagaId != default)
            {
                return;
            }

            var createdMethod = new
            {
                id = m.Id, creator = m.Creator, name = m.Name,
                applicationRate = m.ApplicationRate, creationDate = m.CreationDate
            };
            await _hubContext.Clients.Groups(m.LoggedInUserId.ToString()).SendAsync("ReceiveMethodCreatedMessage", createdMethod);
        }
        private void HandleCreateMethods(CreateMethods createMethods)
        {
            Result <List <Method> > methodsCreationResult = _repository.CreateMethods(createMethods);

            if (methodsCreationResult.IsFailure)
            {
                MethodsCreationFailed failedMethod =
                    new MethodsCreationFailed(
                        methodsCreationResult.Error,
                        createMethods.LoggedInUserId,
                        createMethods.SagaId
                        );
                _kafkaProducer.Produce(failedMethod, METHODS_TOPIC);
                return;
            }

            List <MethodCreated> createdMethods = new List <MethodCreated>();

            foreach (var methodCreationResult in methodsCreationResult.Value)
            {
                MethodCreated createdMethod = new MethodCreated(
                    methodCreationResult.Id,
                    methodCreationResult.Creator,
                    methodCreationResult.Name,
                    methodCreationResult.ApplicationRate,
                    methodCreationResult.CreationDate,
                    createMethods.LoggedInUserId,
                    createMethods.SagaId
                    );
                createdMethods.Add(createdMethod);
            }

            MethodsCreated createdMethodsEvent = new MethodsCreated(createdMethods, createMethods.LoggedInUserId, createMethods.SagaId);

            _kafkaProducer.Produce(createdMethodsEvent, METHODS_TOPIC);
        }