示例#1
0
        ShiftdetailDto IShiftService.OpenShift(string storeEmail, decimal startingCash, int posUserId, string posUser)
        {
            try
            {
                UserEntity user = _userRepository.GetUserByUserName(posUser);
                if (user == null)
                {
                    return(null);
                }
                ShiftEntity shiftEntity = new ShiftEntity();
                shiftEntity.StoreEmail   = storeEmail;
                shiftEntity.StartingCash = startingCash;
                shiftEntity.PosUserId    = posUserId;
                shiftEntity.Available    = true;

                ShiftEntity data = _shiftRepository.GetShift(storeEmail, user.Id);
                ShiftEntity newShift;
                if (data == null)
                {
                    newShift = _shiftRepository.CreateShift(shiftEntity);
                    return(_mapper.Map <ShiftdetailDto>(newShift));
                }
                if (data.Available == true)
                {
                    return(null);
                }
                newShift = _shiftRepository.CreateShift(shiftEntity);
                ShiftdetailDto shiftdetailDto = _mapper.Map <ShiftdetailDto>(newShift);

                return(shiftdetailDto);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        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());
        }