Ejemplo n.º 1
0
        //Esta clase puede existir si la conversión es muy compleja y requiere logica de negocio adicional
        public ConceptoCreatedEvent CommandToEvent(CreateUpdateConceptosCommand command)
        {
            var newEvent = new ConceptoCreatedEvent()
            {
                CreatedAt = DateTime.Now,
                Id        = command.Concepto.Id,
                Codigo    = command.Concepto.Codigo,
                Nombre    = command.Concepto.Nombre,
                Parametro = command.Concepto.Parametro,
                Tipo      = command.Concepto.Tipo
            };

            return(newEvent);
        }
        public async Task <IActionResult> Create([
                                                     FromBody] CreateUpdateConceptosCommand command, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var commandResult = await _mediator.Send(command, cancellationToken);

            if (commandResult.IsSuccess)
            {
                return(CreatedAtRoute(
                           routeName: nameof(GetById),
                           routeValues: new { commandResult.Data.Id },
                           value: commandResult.Data
                           ));
            }

            return(StatusCode(500, new {
                error = commandResult.FailureReason
            }));
        }