public async Task <ICommandResult> Handle(RemoveDeveloperFromProjectCommand command) { command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Operação inválida", command.Notifications)); } var projectDb = await _projectRepository.GetProjectWithDevelopersProject(command.ProjectId); if (projectDb == null) { return(new GenericCommandResult(false, "Projeto não encontrado", command.Notifications)); } var developerDb = await _developerRepository.GetByIdAsync(command.DeveloperId); if (developerDb == null) { return(new GenericCommandResult(false, "Desenvolvedor não encontrado", command.Notifications)); } var developersProjects = projectDb.DeveloperProjects; DeveloperProject founded = null; foreach (var developerProject in developersProjects) { if (developerProject.ProjectId == command.ProjectId && developerProject.DeveloperId == command.DeveloperId) { founded = developerProject; } } await _projectRepository.RemoveDeveloperFromProject(founded); return(new GenericCommandResult(true, "Desenvolvedor removido do projeto com sucesso", new { DeveloperName = developerDb.Name, ProjectName = projectDb.Name })); }
public async Task <GenericCommandResult> RemoveDeveloperFromProject([FromBody] RemoveDeveloperFromProjectCommand command, [FromServices] ProjectHandler handler) { return((GenericCommandResult)await handler.Handle(command)); }