Ejemplo n.º 1
0
        public bool Update(EmployeeUpdateCommand cmd)
        {
            Employee employeeDb = _repositoryEmployee.GetById(cmd.Id) ?? throw new NotFoundException();

            Employee employee = Mapper.Map(cmd, employeeDb);

            return(_repositoryEmployee.Update(employee));
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public IHttpActionResult Put(EmployeeUpdateCommand cmd)
        {
            var validator = cmd.Validate();

            if (!validator.IsValid)
            {
                return(HandleValidationFailure(validator.Errors));
            }

            return(HandleCallback(() => _employeeService.Update(cmd)));
        }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
            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);
            }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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>());
        }
Ejemplo n.º 8
0
 public Task <string> Handle(EmployeeUpdateCommand request, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }
 public void UpdateEmployee(EmployeeUpdateCommand command)
 {
     CommandBus.Dispatch(command);
 }
Ejemplo n.º 10
0
        public async Task <IActionResult> Put(EmployeeUpdateCommand command)
        {
            string response = await _mediator.Send(command);

            return(Ok(response));
        }
 public void UpdateEmployee(EmployeeUpdateCommand command)
 {
     commandFacade.UpdateEmployee(command);
 }