public IResult Handler(CreateAssociationCommand command) { command.Validate(); AddNotifications(command); if (command.Invalid) { return(new CommandResult(false, "Dados inválidos", null, Notifications)); } var employee = _employeeRepository.GetById(command.IdEmployee); if (employee == null) { return(new CommandResult(false, "Esse funcionário não existe no sistema", null, Notifications)); } var services = _serviceRepository.GetByIds(command.IdsService); if (services.Count() != command.IdsService.Count()) { return(new CommandResult(false, "Foram informados serviços que não existe", null, Notifications)); } foreach (var item in services) { _serviceEmployeeRepository.Save(new ServiceEmployee(item.Id, employee.Id)); } return(new CommandResult(true, $"Os serviços selecionados foram associados ao funcionário {employee.Name}", null, Notifications)); }
public IActionResult New([FromBody] CreateAssociationCommand association) { return(Ok(_employeeHadler.Handler(association))); }