public async Task <IActionResult> UpdateStudent(UpdateStudentCommand command) { return(Ok(await mediator.Send(command))); }
public Task <Unit> Handle(UpdateStudentCommand message, CancellationToken cancellationToken) { // 省略... return(Task.FromResult(new Unit())); }
public async Task <IActionResult> Update(UpdateStudentCommand command) => await SendAsync(command, resourceId : command.Id, resource : "student");
// Editar um aluno public ICommandResult Handle(UpdateStudentCommand command) { // Variaveis necessarias Student student = new Student(); Parent parent = new Parent(); Document parentDocument = new Document(); Email parentEmail = new Email(); // Valida os dados do command command.Validate(); // Se for invalido, mostrar as notificações if (command.Invalid) { AddNotifications(command); return(new CommandResult(false, SharedMessages.InvalidOperation, command)); } // Preenchendo os VOs do aluno var studentName = new Name(command.FirstName, command.LastName); var studentAddress = new Address(command.Street, command.Number, command.Neighborhood, command.City, command.StateName, command.Coutry, command.ZipCode, command.Abbr); // Preenchendo o objeto aluno student = new Student(studentName, studentAddress, command.BirthDate, command.ETypeOfEducation, command.AcademicYear, command.Serie, command.Grade, command.Shifts, command.CalledNumber, command.Note); student.ChangeId(command.Id); student.SetSchoolId(command.SchoolId); //Preenchendo o objeto dos responsáveis for (int i = 0; i < command.Parents.Count; i++) { // Preenchendo os VOs do responsável parentDocument = new Document(command.Parents[i].DocumentNumber, command.Parents[i].Type); parentEmail = new Email(command.Parents[i].AddressEmail); // Preenchendo o objeto responsável parent = new Parent(command.Parents[i].ResponsibleName, parentDocument, command.Parents[i].EFamilyType, parentEmail, command.Parents[i].Telephone); parent.ChangeId(command.Parents[i].Id); parent.AddUpdateAlternativeTelephone(command.Parents[i].AlternativeTelephone); parent.AddUpdateContactTelephone(command.Parents[i].ContactTelephone); // Adicionando o responsável ao aluno student.AddParents(parent); } // Caso algum deles retorne erro, mostre as notificações AddNotifications(parentDocument, parentEmail, parent, studentName, studentAddress, student); // Checando as notificações if (Invalid) { return(new CommandResult(false, SharedMessages.InvalidOperation, student)); } // Adicionando ao contexto o objeto aluno _studentRepository.Update(student); // Realizando a confirmação do salvamento do objeto _uow.Commit(); // Retornando informações de sucesso e o objeto preenchido return(new CommandResult(true, SharedMessages.SuccedOperation, student)); }
public async Task <IActionResult> Update([FromBody] UpdateStudentCommand command) { await Mediator.Send(command); return(NoContent()); }
public ICommandResult UpdateStudent([FromBody] UpdateStudentCommand command) { return(_handler.Handle(command)); }
public ICommandResult Put([FromBody] UpdateStudentCommand value) { var result = (CommandResult)_handler.Handle(value); return(result); }