예제 #1
0
        public async Task <CommandResponse> Handle(EmployeeRemoveCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                return(request.CommandResponse);
            }

            var employee = await _employeesRepository.FindById(request.Id);

            if (employee == null)
            {
                request.CommandResponse.ValidationResult.Errors.Add(new ValidationFailure(string.Empty, "employee not found "));
                return(request.CommandResponse);
            }

            // Cretae Employee Event
            employee.Apply(new EmployeeRemoveEvent(employee.Id));

            // TODO Here will Add to Domain Event....

            _employeesRepository.Remove(employee);

            await _eventStoreRepository.SaveAsync <Employee>(employee);

            return(await Commit(_employeesRepository.UnitOfWork));
        }