Exemple #1
0
 private static void ListAllQuotesOfType_WithSamurai(QuoteStyle quoteStyle)
 {
     ch.Line("ListAllQuotesOfType_WithSamurai");
     using (var context = new SamuraiContext())
     {
         foreach (var quote in context.Quotes.Where(q => q.Style == quoteStyle).Include(q => q.Samurai))
         {
             ch.Green($"'{quote.Text}' is a {quoteStyle.ToString().ToLower()} quote by {quote.Samurai.Name}");
         }
     }
 }
        public string[] ReportQuotesOfType(QuoteStyle style)
        {
            var    result      = new List <string>();
            string stylestring = style.ToString().ToLower();

            foreach (var sam in _context.Samurais)
            {
                string name      = sam.Name;
                int    numQuotes = sam.Quotes.Count(x => x.Style == style);
                if (numQuotes == 0)
                {
                    result.Add($"{name} has no {stylestring} quotes");
                }
                else if (numQuotes == 1)
                {
                    result.Add($"{name} has 1 {stylestring} quote");
                }
                else
                {
                    result.Add($"{name} has {numQuotes} {stylestring} quotes");
                }
            }
            return(result.ToArray());
        }