public bool Update(EmployeeUpdateCommand cmd) { Employee employeeDb = _repositoryEmployee.GetById(cmd.Id) ?? throw new NotFoundException(); Employee employee = Mapper.Map(cmd, employeeDb); return(_repositoryEmployee.Update(employee)); }
public async Task <Employee> Put(string id, EmployeeRequestModel request) { var employeeId = new EmployeeId(id); var employeeData = new Employee(employeeId, request.FullName, request.Department, ""); var employeeCommand = new EmployeeUpdateCommand(employeeId, employeeData); await CommandBus.PublishAsync(employeeCommand, CancellationToken.None).ConfigureAwait(false); return(employeeData); }
public IHttpActionResult Put(EmployeeUpdateCommand cmd) { var validator = cmd.Validate(); if (!validator.IsValid) { return(HandleValidationFailure(validator.Errors)); } return(HandleCallback(() => _employeeService.Update(cmd))); }
public void SetUp() { AutoMapperInitializer.Reset(); AutoMapperInitializer.Initialize(); _employee = ObjectMother.GetValidEmployee(); _employeeRegister = Mapper.Map <EmployeeRegisterCommand>(_employee); _employeeUpdate = Mapper.Map <EmployeeUpdateCommand>(_employee); _employeeRemove = Mapper.Map <EmployeeRemoveCommand>(_employee); _mockRepository = new Mock <IEmployeeRepository>(); _mockSpendingRepo = new Mock <ISpendingRepository>(); _service = new EmployeeService(_mockRepository.Object, _mockSpendingRepo.Object); }
public void should_handle_update_employee_command() { // Arrange var inputCommand = new EmployeeUpdateCommand(anyEmployee.EmployeeId, "joe don", "bedford", "*****@*****.**"); EmployeeRepositoryMock .Setup(i => i.ReadAsync(It.IsAny <Guid>())) .ReturnsAsync(anyEmployee); // Act var result = EmployeeUpdateCommandHandlerUnderTest.Handle(inputCommand, default(CancellationToken)).Result; // Assert Assert.Equal(Unit.Value, result); }
public static EmployeeRecord Merge(EmployeeUpdateCommand command) { var recordToUpdate = From(command.EntityToUpdate); recordToUpdate.Email = command.Email; recordToUpdate.EmailLower = command.Email.ToLowerInvariant(); recordToUpdate.EmploymentStartedOn = command.EmploymentStartedOn; recordToUpdate.FirstName = command.FirstName; recordToUpdate.FirstNameLower = command.FirstName.ToLowerInvariant(); recordToUpdate.LastName = command.LastName; recordToUpdate.LastNameLower = command.LastName.ToLowerInvariant(); recordToUpdate.Phone = command.Phone; recordToUpdate.Status = command.Status; recordToUpdate.Title = command.Title; return(recordToUpdate); }
public EmployeeUpdateResponse Handle(EmployeeUpdateCommand command) { // TODO validation var employee = _employeeContext.Employees.FirstOrDefault(e => e.Id == command.Id); if (employee == null) { return(ResponseFactory.Failure <EmployeeUpdateResponse>(EmployeeError.EmployeeDoesntExist)); } if (!ValidateEmailDoesntExist(command.Email)) { return(ResponseFactory.Failure <EmployeeUpdateResponse>(EmployeeError.EmailAlreadyExists)); } employee.FirstName = command.FirstName; employee.LastName = command.LastName; employee.Email = command.Email; return(ResponseFactory.Success <EmployeeUpdateResponse>()); }
public Task <string> Handle(EmployeeUpdateCommand request, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public void UpdateEmployee(EmployeeUpdateCommand command) { CommandBus.Dispatch(command); }
public async Task <IActionResult> Put(EmployeeUpdateCommand command) { string response = await _mediator.Send(command); return(Ok(response)); }
public void UpdateEmployee(EmployeeUpdateCommand command) { commandFacade.UpdateEmployee(command); }