コード例 #1
0
        public async Task <IActionResult> CreateShift(ShiftModel model)
        {
            if (!await EmployeeExists(model.EmployeeId))
            {
                return(new NotFoundResult());
            }

            var shift = model.ToShift();

            if (await _shiftRepository.IsEmployeeAlreadyAssignedAShift(shift, model.EmployeeId))
            {
                return(new BadRequestObjectResult("A shift is already assigned to the employee."));
            }

            _shiftRepository.CreateShift(shift);
            await _shiftRepository.SaveChanges();

            return(new OkResult());
        }