Beispiel #1
0
        public async Task <GetRepairDetailsResponse> GetCustomerRepairAsync(int id, CancellationToken cancellationToken)
        {
            var validator = new IdValidator();
            await validator.ValidateAndThrowAsync(id, null, cancellationToken);

            var result = await _repairRepository.GetAsync(predicate :
                                                          x => x.Id == id &&
                                                          x.CustomerId == _userContextProvider.UserId,
                                                          cancellationToken,
                                                          include : x => x
                                                          .Include(x => x.UsedParts)
                                                          .ThenInclude(x => x.Part)
                                                          .Include(x => x.RequiredRepairTypes)
                                                          .ThenInclude(x => x.RepairType)
                                                          .Include(x => x.Customer)
                                                          .Include(x => x.EmployeeRepairs)
                                                          .ThenInclude(x => x.User)
                                                          .Include(x => x.Invoice));

            if (result == null)
            {
                throw new ServiceException(ErrorCodes.RepairWithGivenIdNotFound, $"Repair with provided id doesn't exist");
            }

            return(_mapper.Map <GetRepairDetailsResponse>(result.FirstOrDefault()));
        }