public async Task CreatInvoice(NewBillDTO dto) { var user = await ServiceUnitOfWork.AccountRepository.FindAsync(dto.UserBill.Id); var trainings = new List <DAL.App.DTO.Training>(); var bill = new Bill() { AppUserId = dto.UserBill.Id, Deadline = dto.Deadline, Total = dto.Total, }; bill = ServiceRepository.AddNewBill(bill); await ServiceUnitOfWork.SaveChangesAsync(); foreach (var trainingdto in dto.Trainings) { var trainingInBill = new TrainingInBill() { BillId = bill.Id, TrainingId = trainingdto.Id }; await ServiceUnitOfWork.TrainingInBillRepository.AddNewTrainingInBill(trainingInBill); var training = await ServiceUnitOfWork.TrainingRepository.FindAsync(trainingdto.Id); trainings.Add(training); } await ServiceUnitOfWork.SaveChangesAsync(); }