public ActionResult <Company> Hire([FromRoute] int companyId, [FromRoute] int contactId)
        {
            var command = new HireEmployeeCommand {
                CompanyId = companyId, ContactId = contactId
            };
            var company = _companyService.Hire(command);

            return(Ok(company));
        }
Example #2
0
        public async Task <IHttpActionResult> HireEmployee(Guid id, HireEmployeeCommand command)
        {
            command.Validate();
            command.Id = id;

            await _bus.DispatchAsync(command);

            return(Ok());
        }
Example #3
0
        /// <inheritdoc />
        public async Task HandleAsync(HireEmployeeCommand command)
        {
            var company = await _companyRepository.GetAsync(command.Id);

            if (company == null)
            {
                throw new CommandHandlerNotFoundException("Company Not Found");
            }

            company.HireEmployee(new Employee(new FullName(command.FirstName, command.LastName), new NationalCode(command.NationalCode)));

            await _unitOfWork.CommitAsync();
        }
        public Company Hire(HireEmployeeCommand command)
        {
            var company = GetCompany(command.CompanyId);

            company.CompanyEmployees.Add(new CompanyEmployees
            {
                ContactId = command.ContactId
            });

            _contactsContext.SaveChanges();

            return(company);
        }
Example #5
0
        public async Task <ActionResult> Create([FromBody] HireEmployeeCommand command)
        {
            try
            {
                var result = await mediator.Send(command);

                return(Created($"/employees/{result.Id}", result));
            }
            catch (BusinessException ex)
            {
                return(ex.GetError());
            }
        }