public async Task <Unit> Handle(UpdateProfessorCommand command, CancellationToken cancellationToken)
        {
            //var professor = new Professor
            //{
            //    Id = Guid.Parse(request.Id),
            //    Nome = request.Nome,
            //    Email = request.Email
            //};

            var professor = _mapper.Map <Professor>(command);

            //validando o professor
            var validation = new ProfessorValidation().Validate(professor);

            if (!validation.IsValid)
            {
                throw new ValidationException(validation.Errors);
            }

            _professorDomainService.Update(professor);

            await _mediator.Publish(new ProfessorNotification
            {
                Professor = professor,
                Action    = ActionNotification.Atualizar
            });

            return(Unit.Value);
        }
Exemplo n.º 2
0
        public ProfessorResponseModel Update(int id, ProfessorRequestModel request)
        {
            UpdateProfessorCommand command = new UpdateProfessorCommand(id, request.FirstName, request.LastName);
            Professor professor            = updateProfessorHandler.Handle(command);

            ProfessorResponseModel response = professorsMapper.Map(professor);

            return(response);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Put(UpdateProfessorCommand command)
        {
            try
            {
                await _professorApplicationService.Update(command);

                return(Ok(new { Message = "Professor Atualizado com sucesso." }));
            }
            catch (ValidationException e)
            {
                return(BadRequest(ValidationAdapter.Parse(e.Errors)));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
 public async Task Update(UpdateProfessorCommand command)
 {
     await _mediator.Send(command);
 }