Ejemplo n.º 1
0
        //public async Task<List<GetRepairsResponse>> GetCustomerRepairsAsync(int customerId, CancellationToken cancellationToken)
        //{
        //    var validator = new IdValidator();
        //    await validator.ValidateAndThrowAsync(customerId, null, cancellationToken);

        //    var result = await _repairRepository.GetAsync(predicate: x => x.CustomerId == customerId, cancellationToken,
        //        include: x => x
        //        .Include(x => x.Customer)
        //        .Include(x => x.EmployeeRepairs)
        //            .ThenInclude(x => x.User));

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

        //    return _mapper.Map<List<GetRepairsResponse>>(result);
        //}

        public async Task UpdateRepairDescriptionAsync(UpdateRepairDescriptionRequest request, CancellationToken cancellationToken)
        {
            var validator = new UpdateRepairDescriptionRequestValidator();
            await validator.ValidateAndThrowAsync(request, null, cancellationToken);

            var result = await _repairRepository.GetByIdAsync(request.RepairId, cancellationToken);

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

            result.Description = request.NewDescription;

            await _repairRepository.UpdateAsync(cancellationToken, result);
        }
        public async Task <IActionResult> UpdateRepairDescription([FromBody] UpdateRepairDescriptionRequest request, CancellationToken cancellationToken)
        {
            await _repairService.UpdateRepairDescriptionAsync(request, cancellationToken);

            return(Ok());
        }