Ejemplo n.º 1
0
        public async Task <IActionResult> Update([FromBody] UpdatePointCommand command)
        {
            var result = await _bus.Send(command);

            return(result.Success
                ? NoContent()
                : Error(result.ErrorMessage));
        }
        public async Task <DomainResult> Handle(UpdatePointCommand command, CancellationToken cancellationToken)
        {
            var point = await _pointRepository.FindAsync(command.Id);

            if (point is null)
            {
                return(DomainResult.Failure <string>("Point not found"));
            }

            point.Update(command);

            var alreadyExists = await _pointRepository.AlreadyExistsAsync(x => x.IsTheSame(point));

            if (alreadyExists)
            {
                return(DomainResult.Failure <string>("Point already exists", HttpStatusCode.Conflict));
            }

            await _pointRepository.UpdateAsync(point);

            await _mediator.Publish(new PointUpdatedEvent(point));

            return(DomainResult.Ok());
        }
Ejemplo n.º 3
0
 internal void Update(UpdatePointCommand command)
 {
     Name      = command.Name;
     UpdatedAt = DateTime.UtcNow;
 }