コード例 #1
0
        public async Task <IActionResult> SwapShifts(SwapShiftsModel model)
        {
            var shiftOne = await _shiftRepository.GetShift(model.FirstShiftId);

            var shiftTwo = await _shiftRepository.GetShift(model.SecondShiftId);

            if (shiftOne == null || shiftTwo == null)
            {
                return(new BadRequestObjectResult("One or more shifts could not be found with the supplied ID's."));
            }

            if (DoesTheShiftsBelongToTheSameEmployee(shiftOne, shiftTwo))
            {
                return(new BadRequestObjectResult("The shifts can not be swapped since they belong to the same employee."));
            }

            if (await CanEmployeesSwapShifts(shiftOne, shiftTwo))
            {
                return(new BadRequestObjectResult("One or more employees are not able to swap shift."));
            }

            var temp = shiftOne.EmployeeId;

            shiftOne.EmployeeId = shiftTwo.EmployeeId;
            shiftTwo.EmployeeId = temp;

            await _shiftRepository.SaveChanges();

            return(new OkObjectResult("The shifts has been swapped."));
        }
コード例 #2
0
 public async Task <IActionResult> SwapShifts(SwapShiftsModel model)
 {
     return(await _shiftService.SwapShifts(model));
 }