public void Execute() { Interval confines = _view.GetLimitFields(); List <Book> books = _context.GetAllBooks(); List <string> outputs = new List <string>(); foreach (Book book in books) { if (book.Limit.from >= confines.from && book.Limit.till <= confines.till) { string value = $"\"{book.Title}\" : {book.Limit.ToString()}"; _view.SetOutputField(value); outputs.Add(value); } } string filename = _view.GetFileNameField(); WordUtils.PrintToWord(outputs, filename); }
public void Execute() { List <Book> books = _context.GetAllBooks(); Book cheapestBook = null; foreach (Book book in books) { if (cheapestBook == null || book.Price < cheapestBook.Price) { cheapestBook = book; } } if (cheapestBook != null) { string value = $"The cheapest book is \"{cheapestBook.Title}\" and its price = {cheapestBook.Price}"; _view.SetOutputField(value); string filename = _view.GetFileNameField(); WordUtils.PrintToWord(value, filename); } }