Example #1
0
        public async Task <IActionResult> CreateEmployee([FromBody] EmployeeForCreate employee)
        {
            var employeeFromCreate = await _mediator.Send(new CreateEmployeeCommand(employee));

            if (employeeFromCreate == null)
            {
                throw new InvalidOperationException("Expected a non-null employee from employee creation");
            }

            return(CreatedAtAction(nameof(GetEmployee), new { employeeId = employeeFromCreate.Id }, employeeFromCreate));
        }
Example #2
0
        public CreateEmployeeCommand(EmployeeForCreate employeeForCreate)
        {
            if (employeeForCreate is null)
            {
                throw new ArgumentNullException(nameof(employeeForCreate));
            }

            FirstName = employeeForCreate.FirstName;
            LastName  = employeeForCreate.LastName;
            Title     = employeeForCreate.Title;
            BirthDate = DateTime.Parse(employeeForCreate.BirthDate, CultureInfo.CurrentCulture);
            HireDate  = DateTime.Parse(employeeForCreate.HireDate, CultureInfo.CurrentCulture);
        }