示例#1
0
        public Task <bool> Handle(UpdateDeveloperCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(Task.FromResult(false));
            }

            var model = developerRepository.GetById(request.Id);

            if (model == null)
            {
                bus.RaiseEvent(new DomainNotification(request.MessageType, "This Developer not found."));
                return(Task.FromResult(false));
            }

            model.DescriptionEN = request.DescriptionEN;
            model.DescriptionPT = request.DescriptionPT;
            model.EntityState   = request.EntityState;
            developerRepository.Update(model);

            if (Commit())
            {
                bus.RaiseEvent(new DeveloperUpdatedEvent(model.Id, model.DescriptionPT, model.DescriptionEN, model.EntityState, model.DateCreated));
            }
            return(Task.FromResult(true));
        }
        public async Task <ActionResult <DeveloperDto> > Update(int id, [FromBody] UpdateDeveloperCommand command)
        {
            command.Id = id;
            var res = await Mediator.Send(command);

            return(Ok(await Mediator.Send(new GetDeveloperDetailQuery {
                Id = res
            })));
        }
示例#3
0
        public async Task <ICommandResult> Handle(UpdateDeveloperCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "Operação inválida", command.Notifications));
            }

            var developerDb = await _developerRepository.GetByIdAsync(command.Id);

            if (developerDb == null)
            {
                return(new GenericCommandResult(false, "Desenvolvedor não encontrado", command.Notifications));
            }


            _mapper.Map(command, developerDb);

            await _developerRepository.UpdateAsync(developerDb);

            return(new GenericCommandResult(true, "Desenvolvedor alterado com sucesso", developerDb));
        }
 public async Task <GenericCommandResult> Update([FromBody] UpdateDeveloperCommand command, [FromServices] DeveloperHandler handler)
 {
     return((GenericCommandResult)await handler.Handle(command));
 }
示例#5
0
        public async Task <IActionResult> Edit([FromBody] UpdateDeveloperCommand command, [FromRoute] Guid id)
        {
            var result = await _mediator.Send(command.IncludeId(id));

            return(Ok(result));
        }