private void button7_Click(object sender, EventArgs e)
        {
            PrintThatFetchingData();
            using (var db = new EFSchoolSystemContext())
            {
                var model = new ResultsModel();
                var rnd   = new Random();
                model.Page           = rnd.Next(1, 1000);
                model.ResultsPerPage = rnd.Next(10, 100);
                var schools = db.Schools
                              .OrderBy(s => s.PostalZipCode)
                              .Skip(model.Page * model.ResultsPerPage)
                              .Take(model.ResultsPerPage)
                              .ToList();

                var sb = new StringBuilder();
                foreach (var school in schools)
                {
                    sb.Append(school.Name);
                    sb.Append(Environment.NewLine);
                }
                textBox_Output.Text = sb.ToString();
            }
        }
Exemplo n.º 2
0
        //Page through schools
        public string DoProblem7()
        {
            using (var db = new EFSchoolSystemContext())
            {
                var model = new ResultsModel();
                var rnd   = new Random();
                model.Page           = rnd.Next(1, 1000);
                model.ResultsPerPage = rnd.Next(10, 100);
                var resultsToSkip = model.Page * model.ResultsPerPage;

                List <string> schools = db.Schools
                                        .OrderBy(s => s.PostalZipCode)
                                        .Skip(resultsToSkip)
                                        .Take(model.ResultsPerPage)
                                        .Select(s => s.Name)
                                        .ToList();

                foreach (var school in schools)
                {
                    _outputBuffer.Append(school);
                }
                return(_outputBuffer.ToString());
            }
        }
        private void button7_Click(object sender, EventArgs e)
        {
            PrintThatFetchingData();
            using (var db = new EFSchoolSystemContext())
            {
                var model = new ResultsModel();
                var rnd = new Random();
                model.Page = rnd.Next(1, 1000);
                model.ResultsPerPage = rnd.Next(10, 100);
                var schools = db.Schools
                    .OrderBy(s => s.PostalZipCode)
                    .Skip(model.Page * model.ResultsPerPage)
                    .Take(model.ResultsPerPage)
                    .ToList();

                var sb = new StringBuilder();
                foreach (var school in schools)
                {
                    sb.Append(school.Name);
                    sb.Append(Environment.NewLine);
                }
                textBox_Output.Text = sb.ToString();
            }
        }