public async Task <ActionResult <EmploymentConfirmation> > PostEmployment([FromBody] EmploymentPostBody employmentPostBody)
        {
            var newEmploymentConfirmation = await _service.CreateEmployment(employmentPostBody);

            if (newEmploymentConfirmation == null)
            {
                return(BadRequest());
            }

            return(CreatedAtAction(nameof(GetEmploymentById),
                                   new { carStationId = newEmploymentConfirmation.CarStationId, employeeId = newEmploymentConfirmation.EmployeeId },
                                   newEmploymentConfirmation));
        }
Beispiel #2
0
        public async Task <EmploymentConfirmation> CreateEmployment(EmploymentPostBody employmentPostBody)
        {
            EmployeeCarStation newEmployment = new()
            {
                EmployeeId   = employmentPostBody.EmployeeId,
                CarStationId = employmentPostBody.CarStationId,
                StartDate    = employmentPostBody.StartDate,
                EndDate      = employmentPostBody.EndDate
            };
            await _context.Set <EmployeeCarStation>().AddAsync(newEmployment);

            await _context.SaveChangesAsync();

            _logger.LogInformation("CreateEmploymentAsync() Executed!");
            return(await Task.FromResult(_mapper.Map <EmploymentConfirmation>(newEmployment)));
        }