public async Task <ActionResult> Delete(int id) { var command = new DeleteEmployeeCommand(id); await _mediator.Send(command); return(NoContent()); }
protected void repEmployees_ItemCommand(object source, RepeaterCommandEventArgs e) { ImageButton action = (ImageButton)e.CommandSource; string actionString = action.ID; if (action.ID.Equals("delete")) { try { string id = ((Label)repEmployees.Items[e.Item.ItemIndex].FindControl("employeeId")).Text; Employee employeeToDelete = new Employee(Int32.Parse(id)); DeleteEmployeeCommand cmd = new DeleteEmployeeCommand(employeeToDelete); cmd.Execute(); int result = cmd.GetResult(); if (result == 200) { ScriptManager.RegisterStartupScript(this, this.GetType(), "randomText", "sweetAlert('Se ha eliminado el empleado exitosamente', 'success', '/site/employees/hrm/employeelist.aspx')", true); } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "randomText", "errorSweetAlert('El empleado no ha podido ser eliminado', 'error')", true); } } catch (Exception ex) { ScriptManager.RegisterStartupScript(this, this.GetType(), "randomText", "errorSweetAlert('El empleado no ha podido ser eliminado', 'error')", true); } } else if (action.ID.Equals("modify")) { string email = ((Label)repEmployees.Items[e.Item.ItemIndex].FindControl("employeeEmail")).Text; Session["CONSULTED_EMAIL"] = email; Response.Redirect("~/site/employees/hrm/employeedata.aspx", false); } }
public void Setup() { _employeeRepo = new Mock <IEmployeeRepository>(); _employeeRepo.Setup(x => x.DeleteEmployee(It.IsAny <Guid>())); _command = new DeleteEmployeeCommand(_employeeRepo.Object); }
public async Task <IActionResult> DeleteEmployee(int id) { var command = new DeleteEmployeeCommand(id); var result = await _mediator.Send(command); return(Ok(result)); }
public async Task <EmployeeDTO> Handle(DeleteEmployeeCommand request, CancellationToken cancellationToken) { var employee = await _unitOfWork.GetRepository <Employee>().FindAsync(request.Id); //Checks if we are trying to delete manager or CEO if (employee.IsManager || employee.IsCEO) { // Gets a list of employees that the CEO/Manager is managing var managedList = _unitOfWork.GetRepository <Employee>().GetAll().Where(t => t.ManagerId == employee.Id); //If the manager/ceo isn't managing any employees/manager employee will be deleted from table if (!managedList.Any()) { _unitOfWork.GetRepository <Employee>().Delete(employee); await _unitOfWork.SaveChangesAsync(); return(_mapper.Map <EmployeeDTO>(employee)); } } // if none of the following conditons are true it will delete the employee else { _unitOfWork.GetRepository <Employee>().Delete(employee); await _unitOfWork.SaveChangesAsync(); return(_mapper.Map <EmployeeDTO>(employee)); } return(null); }
public EmployeeViewModel(IEmployeeRepository employeeRepository, ISubdivisionRepository subdivisionRepository) { AddEmployeeCommand = new AddEmployeeCommand(this); DeleteEmployeeCommand = new DeleteEmployeeCommand(this, employeeRepository); SaveEmployeesCommand = new SaveEmployeesCommand(this, employeeRepository); RefreshEmployeesCommand = new RefreshEmployeesCommand(this, employeeRepository, subdivisionRepository); RefreshEmployeesCommand.Execute(null); }
public void ShouldRecognizeDeleteEmployeeCommand(int id) { var expectedDeleteEmployeeCommand = new DeleteEmployeeCommand(id); var command = $"DelEmp {id}"; var deleteEmployeeCommand = DeleteEmployeeCommandParser.Parse(command); deleteEmployeeCommand.Should().Be(expectedDeleteEmployeeCommand); }
public void ShouldRequireValidEmployeeId() { var command = new DeleteEmployeeCommand { Id = 99999 }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public async Task <Response> Handle(DeleteEmployeeCommand request, CancellationToken cancellationToken) { var employee = repository.GetById(request.Id); repository.Delete(employee); await repository.SaveChanges(); return(await Task.FromResult(new Response(employee))); }
public async Task <IActionResult> Delete(int employeeId) { DeleteEmployeeCommand deleteEmployeeCommand = new DeleteEmployeeCommand(); deleteEmployeeCommand.EmployeeId = employeeId; await this._mediator.Send(deleteEmployeeCommand); return(NoContent()); }
public async Task <ActionResult> Delete(int matricule) { var command = new DeleteEmployeeCommand { Matricule = matricule }; await _employeeHandler.HandleAsync(command).ConfigureAwait(false); return(StatusCode(204)); }
public async Task <IActionResult> Delete(int id, string confirm = null) { var deleteEmployeeCommand = new DeleteEmployeeCommand() { EmployeeId = id }; var result = await Mediator.Send(deleteEmployeeCommand); return(RedirectToAction("List")); }
public IActionResult DeleteLocation(Guid employeeId) { EnsureArg.IsNotEmpty(employeeId); var command = new DeleteEmployeeCommand(employeeId); CommandDispatcher.Execute(command); return(NoContent()); }
public async Task <IActionResult> Delete(DeleteEmployeeCommand deleteEmployeeCommand) { var result = await _mediator.Send(deleteEmployeeCommand); if (!result.Success) { return(BadRequest(result.Message)); } return(Ok(result.Message)); }
public MainViewModel(IEmployeeRepository employeeRepository) { EmployeeRepository = employeeRepository; Add = new AddEmployeeCommand(this); Save = new SaveEmployeeCommand(this); Delete = new DeleteEmployeeCommand(this); Next = new SelectNextCommand(this); Prev = new SelectPreviosCommand(this); LoadPeople().Await(HandleException); }
private void InvalidateCommands() { DeleteEmployeeCommand.RaiseCanExecuteChanged(); EditEmployeeCommand.RaiseCanExecuteChanged(); EditCOACommand.RaiseCanExecuteChanged(); DeleteCOACommand.RaiseCanExecuteChanged(); SaveCommand.RaiseCanExecuteChanged(); CancelCommand.RaiseCanExecuteChanged(); EditAttributeCommand.RaiseCanExecuteChanged(); DeleteAttributeCommand.RaiseCanExecuteChanged(); }
public async Task <IActionResult> DeleteEmployee(int id) { _logger.Debug("Delete employee with id", id); var command = new DeleteEmployeeCommand { EmployeeId = id }; await _mediator.Send(command); return(Ok()); }
public IResult Handler(DeleteEmployeeCommand command) { var employee = _employeeRepository.GetById(command.Id); if (employee == null) { return(new CommandResult(false, $"Funcionário com o id {command.Id} não existe", null, Notifications)); } _employeeRepository.Delete(employee); return(new CommandResult(true, "Funcionário excluído com sucesso", null, Notifications)); }
private void InvalidateCommands() { EditFeeScheuleCommand.RaiseCanExecuteChanged(); SaveCommand.RaiseCanExecuteChanged(); PrintCommand.RaiseCanExecuteChanged(); CancelCommand.RaiseCanExecuteChanged(); DeleteCommand.RaiseCanExecuteChanged(); EditAttributeCommand.RaiseCanExecuteChanged(); DeleteAttributeCommand.RaiseCanExecuteChanged(); DeleteFeeScheuleCommand.RaiseCanExecuteChanged(); NewOrderCommand.RaiseCanExecuteChanged(); EditContactCommand.RaiseCanExecuteChanged(); DeleteContactCommand.RaiseCanExecuteChanged(); EditEmployeeCommand.RaiseCanExecuteChanged(); DeleteEmployeeCommand.RaiseCanExecuteChanged(); }
public EmployeeListViewModel(IMessageBroker messageBroker, IEmployeeService employeeService, NewEmployeeCommand newEmployeeCommand, EditEmployeeCommand editEmployeeCommand, DeleteEmployeeCommand deleteEmployeeCommand) { this.messageBroker = messageBroker; this.employeeService = employeeService; NewCommand = newEmployeeCommand; EditCommand = editEmployeeCommand; DeleteCommand = deleteEmployeeCommand; employees = new ObservableCollection <Employee>(); NavigationCommands = new List <CommandBase>() { NewCommand, DeleteCommand }; SubscribeMessages(); }
// constructor public EmployeeViewModel() { dbConnectionString = Properties.Settings.Default.DBConnectionString; // initialize button enable logic bCanDelete = false; bCanAdd = true; bCanEdit = false; bCanUpdate = false; bCanCancel = false; // initialize control commands AddEmployee = new AddEmployeeCommand(this); EditEmployee = new EditEmployeeCommand(this); UpdateEmployee = new UpdateEmployeeCommand(this); DeleteEmployee = new DeleteEmployeeCommand(this); CancelChanges = new CancelChangesCommand(this); // retrieve employee list and populate DataGrid control FillDataGrid(); SelectedItem = -1; OnPropertyChanged("SelectedItem"); }
public async Task <DeleteEmployeeByIdResponse> Handle(DeleteEmployeeByIdRequest request, CancellationToken cancellationToken) { if (request.AuthenticatorRole == AppRole.Employee) { return(new DeleteEmployeeByIdResponse() { Error = new ErrorModel(ErrorType.Unauthorized) }); } var query = new GetEmployeeQuery() { Id = request.EmployeeId, CompanyId = request.AuthenticatorCompanyId }; var employee = await queryExecutor.Execute(query); if (employee == null) { return(new DeleteEmployeeByIdResponse() { Error = new ErrorModel(ErrorType.NotFound) }); } var command = new DeleteEmployeeCommand() { Parameter = employee }; var deletedEmployee = await commandExecutor.Execute(command); return(new DeleteEmployeeByIdResponse { Data = deletedEmployee }); }
public async Task <Unit> Delete([FromRoute] int id, DeleteEmployeeCommand cmd) { cmd.Id = id; return(await _mediator.Send(cmd)); }
public async Task <ActionResult> Delete(DeleteEmployeeCommand EmployeeId) { return(Ok(await _mediator.Send(EmployeeId))); }
public void DeleteEmployee(int Id) { var deleteEmployee = new DeleteEmployeeCommand(Id); _bus.SendCommand(deleteEmployee); }
/// <summary> /// Handles the DeleteEmployee command /// </summary> /// <param name="command">The command</param> /// <returns></returns> public async Task HandleAsync(DeleteEmployeeCommand command) { var employeeDto = EmployeeDto.InitEmployeeMatricule(command.Matricule); await _employeeDal.DeleteEmployeeAsync(employeeDto); }
public async Task <IActionResult> DeleteEmployee(int id) { var deleteEmployeeCommand = new DeleteEmployeeCommand(id); return(Ok(await Mediator.Send(deleteEmployeeCommand))); }
public static void DeleteEmployee(int ID) { var command = new DeleteEmployeeCommand(ID); handleCommand(command); }
public async Task <ActionResult <int> > Delete(DeleteEmployeeCommand command) { return(await Mediator.Send(command)); }
public async Task <IActionResult> Delete([FromBody] DeleteEmployeeCommand request) { var result = await _mediator.Send(request); return(Ok(result)); }