Esempio n. 1
0
        public async Task <IActionResult> Post([FromBody] Trace t)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var trace = _traceRepository.Add(t);
            await _traceRepository.SaveAsync();

            await EnsureOriginAsync(t);

            return(CreatedAtAction(nameof(Get), new { TraceId = trace.TraceId }, trace));
        }
Esempio n. 2
0
        public async Task <bool> Handle(CreateTraceCommand message, CancellationToken cancellationToken)
        {
            // Add/Update the Buyer AggregateRoot
            // DDD patterns comment: Add child entities and value-objects through the Order Aggregate-Root
            // methods and constructor so validations, invariants and business logic
            // make sure that consistency is preserved across the whole aggregate


            //Create a new trace.
            var trace = new Trace(
                message.InvestmentId,
                message.ExchangeId,
                message.BaseCurrency,
                message.QuoteCurrency
                );


            _traceRepository.Add(trace);

            try
            {
                await _traceRepository.UnitOfWork
                .SaveChangesAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Create trace failed. \n" +
                                  "Error Message: " + ex.Message);

                return(false);
            }



            this._eventBus.Publish(new TraceCreatedIntegrationEvent(
                                       trace.TraceId,
                                       trace.Investment.InvestmentId,
                                       trace.Market.ExchangeId,
                                       trace.Market.BaseCurrency,
                                       trace.Market.QuoteCurrency
                                       ));

            return(true);
        }