public async Task <Invoice> GenerateReport([FromHeader] int userId) { Invoice invoice = new Invoice() { Equipments = new List <InvoiceOfEquipment>() }; var userEquipments = await _unitOfWork.UserEquipmentRepository.GetAsync(x => x.UserId == userId); var equipmentTypes = await _unitOfWork.EquipmentTypesRepository.GetAsync(); foreach (var item in userEquipments) { var item1 = item; var equipment = await _unitOfWork.EquipmentsRepository.Query(x => x.Id == item1.EquipmentId) .SingleAsync(); item.EquipmentTypeId = equipment.Type; var price = _priceCalculator.CalculateRentalFee(equipment, item.RentDay, _unitOfWork.RentalFeeTypesRepository.Query()); invoice.TotalPrice += price; var equipmentType = equipmentTypes.Single(x => x.Id == equipment.Type); invoice.Equipments.Add(new InvoiceOfEquipment { InvoiceId = item.Id, EquipmentName = equipment.Name, EquipmentType = equipmentType.Name, EquipmentRentalDay = item.RentDay, EquipmentRentalFee = price, InvoiceDate = item.OperationDate, EquipmentId = item.EquipmentId }); } invoice.LoyaltPoint = _priceCalculator.CalculateLoyaltyPoint(userEquipments); return(invoice); }