示例#1
0
        public async Task <IActionResult> AddEmployeeAsync([FromBody] Infrastructure.Entities.Employee employee)
        {
            var userIdentity = Request.Headers["claims_userid"];

            if (userIdentity.Count == 0)
            {
                return(NotFound(new { Message = $"You are not authorized to add employee." }));
            }

            employee.CreatedBy = employee.ModifiedBy = userIdentity;

            try
            {
                // Commit Add Employee
                var addedEmployee = await _employeeService.AddEmployee(employee);

                var eployeeChangedEvent = new EmployeeAddIntegrationEvent(employee.Id,
                                                                          employee.FirstName,
                                                                          employee.LastName,
                                                                          employee.ModifiedBy);

                await _employeeIntegrationEventService.AddAndSaveEventAsync(eployeeChangedEvent);

                await _employeeIntegrationEventService.PublishEventsThroughEventBusAsync(eployeeChangedEvent);

                return(Ok(employee.Id));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#2
0
        public async Task <bool> Handle(CreateEmployeePermanentCommand request, CancellationToken cancellationToken)
        {
            // Add Integration event to clean the basket
            var employeePermanentCreatedIntegrationEvent = new EmployeePermanentCreatedIntegrationEvent(request.EmpId);
            await _employeeIntegrationEventService.AddAndSaveEventAsync(employeePermanentCreatedIntegrationEvent);

            var Employee = new Dmoain.AggregatesModel.EmployeeAggregate.Employe(request.EmpId,
                                                                                request.Name,
                                                                                request.Address,
                                                                                request.Phone
                                                                                );

            _Repository.Add(Employee);


            return(await _Repository.UnitOfWork.SaveEntitiesAsync(cancellationToken));
        }