public static async Task GenerateDiscountCodes(int ammount) { List <DiscountCard> discountCards = new List <DiscountCard>(); while (ammount > 0) { for (int i = 0; i < ammount; i++) { string code = RandomTextGenerator.Generate(8); var discountCard = new DiscountCard() { DiscountCode = code }; discountCards.Add(discountCard); } discountCards = RemoveCommonCodeFetcher(discountCards); ammount -= discountCards.Count; } var convertedDiscountCards = DiscountCardToDto(discountCards); AccessContext ac = new AccessContext(); await ac.InsertMultipleCodes(convertedDiscountCards); }