public HttpResponseMessage Get() { var students = StudentsRepository.GetAllStudents(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, students); return(response); }
public ActionResult Show() { var students = StudentsRepository.GetAllStudents(this.CurrentUser.Class_id); StudentsViewModel vm = new StudentsViewModel() { AllStudents = students }; return(View(vm)); }
private void FillStudentsListBox() { studentsListBox.Items.Clear(); var context = new LibraryContext(); _studentsRepository = new StudentsRepository(context); foreach (var student in _studentsRepository.GetAllStudents()) { studentsListBox.Items.Add($"{student.StudentId}. {student.FirstName} {student.LastName}"); } }
private static void LinqExtensionMethodsExamples() { var studentsRepository = new StudentsRepository(); var students = studentsRepository.GetAllStudents(); // where var someStudents = students.Where(st => st.Name == "Ivan" || st.Name == "Pesho"); PrintCollection(someStudents); // first Student first = students.FirstOrDefault(st => st.Courses.Count == 4); // First Console.WriteLine(first); // select var projectedItems = students.Select( st => new Student { Name = st.Id.ToString(), Courses = new List<Course>() }); PrintCollection(projectedItems); // select to annonymous var annStudents = students.Select(st => new { Id = st.Id, Courses = st.Courses.Count }); PrintCollection(annStudents); // order by var ordered = students.OrderBy(st => st.Courses.Count).ThenBy(st => st.Name); PrintCollection(ordered); // any bool checkAny = students.Any(st => st.Name.StartsWith("I")); Console.WriteLine(checkAny); // all bool checkAll = students.All(st => st.Name != string.Empty); Console.WriteLine(checkAll); checkAll = students.All(st => st.Id > 2); Console.WriteLine(checkAll); // ToList and ToArray Student[] arrayOfStudents = students.ToArray(); PrintCollection(arrayOfStudents); List<Student> listOfStudents = arrayOfStudents.ToList(); PrintCollection(listOfStudents); // reading string of numbers separated by space int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); PrintCollection(numbers); // reverse students.Reverse(); PrintCollection(students); // average double averageCourses = students.Average(st => st.Courses.Count); Console.WriteLine(averageCourses); // max int max = students.Max(st => st.Courses.Count); Console.WriteLine(max); // min int min = students.Min(st => st.Courses.Count); Console.WriteLine(min); // count int count = students.Count(st => st.Name.Length > 4); Console.WriteLine(count); // sum int sum = students.Sum(st => st.Courses.Count); Console.WriteLine(sum); // extension methods var someCollection = students.Where(st => st.Id > 1) .OrderBy(st => st.Name) .ThenBy(st => st.Courses.Count) .Select(st => new { Name = st.Name, Courses = st.Courses.Count }) .ToArray(); PrintCollection(someCollection); // nesting var someOtherStudents = students.Where(st => st.Courses.Any(c => c.Name == "OOP")).OrderBy(st => st.Name); PrintCollection(someOtherStudents); }
private static void LinqExtensionMethodsExamples() { var studentsRepository = new StudentsRepository(); var students = studentsRepository.GetAllStudents(); // where var someStudents = students.Where(st => st.Name == "Ivan" || st.Name == "Pesho"); PrintCollection(someStudents); //1; Name: Ivan; Courses: 2 //3; Name: Pesho; Courses: 2 // first Student first = students.FirstOrDefault(st => st.Courses.Count == 4); // First Console.WriteLine(first); // select var projectedItems = students.Select( st => new Student { Name = st.Id.ToString(), Courses = new List <Course>() }); PrintCollection(projectedItems); //0; Name: 1; Courses: 0 //0; Name: 2; Courses: 0 //0; Name: 3; Courses: 0 // select to annonymous var annStudents = students.Select(st => new { Id = st.Id, Courses = st.Courses.Count }); PrintCollection(annStudents); //{ Id = 1, Courses = 2 } //{ Id = 2, Courses = 3 } //{ Id = 3, Courses = 2 } // order by var ordered = students.OrderBy(st => st.Courses.Count).ThenBy(st => st.Name); PrintCollection(ordered); //1; Name: Ivan; Courses: 2 //3; Name: Pesho; Courses: 2 //2; Name: Gosho; Courses: 3 // any bool checkAny = students.Any(st => st.Name.StartsWith("I")); Console.WriteLine(checkAny);//True // all bool checkAll = students.All(st => st.Name != string.Empty); Console.WriteLine(checkAll); //True checkAll = students.All(st => st.Id > 2); Console.WriteLine(checkAll); //False // ToList and ToArray Student[] arrayOfStudents = students.ToArray(); PrintCollection(arrayOfStudents); //1; Name: Ivan; Courses: 2 //2; Name: Gosho; Courses: 3 //3; Name: Pesho; Courses: 2 List <Student> listOfStudents = arrayOfStudents.ToList(); PrintCollection(listOfStudents); //1; Name: Ivan; Courses: 2 //2; Name: Gosho; Courses: 3 //3; Name: Pesho; Courses: 2 // reading string of numbers separated by space int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();//1 2 3 PrintCollection(numbers); //1 //2 //3 // reverse students.Reverse(); PrintCollection(students); //1; Name: Ivan; Courses: 2 //2; Name: Gosho; Courses: 3 //3; Name: Pesho; Courses: 2 // average double averageCourses = students.Average(st => st.Courses.Count); Console.WriteLine(averageCourses);//2,33333333333333 // max int max = students.Max(st => st.Courses.Count); Console.WriteLine(max);//3 // min int min = students.Min(st => st.Courses.Count); Console.WriteLine(min);//2 // count int count = students.Count(st => st.Name.Length > 4); Console.WriteLine(count);//2 // sum int sum = students.Sum(st => st.Courses.Count); Console.WriteLine(sum);//7 // extension methods var someCollection = students.Where(st => st.Id > 1) .OrderBy(st => st.Name) .ThenBy(st => st.Courses.Count) .Select(st => new { Name = st.Name, Courses = st.Courses.Count }) .ToArray(); PrintCollection(someCollection); //{ Name = Gosho, Courses = 3 } //{ Name = Pesho, Courses = 2 } // nesting var someOtherStudents = students.Where(st => st.Courses.Any(c => c.Name == "OOP")).OrderBy(st => st.Name); PrintCollection(someOtherStudents); //2; Name: Gosho; Courses: 3 //1; Name: Ivan; Courses: 2 }
private static void WriteAttendanceStats(_Worksheet newWorksheet, int semester, int class_id) { var students = StudentsRepository.GetAllStudents(class_id); int nothing = 0; int neizvineni = 0; List <Student> studentsNeizv = new List <Student>(); if (semester % 20 == 1) { nothing = students.Where(s => s.Attendances.Where(a => a.Date1.Month >= 2 && a.Date1.Month <= 6).Count() == 0).Count(); studentsNeizv = students.Where(s => s.Attendances .Where(a => (a.Att_type == 0 || a.Att_type == 1) && (a.Date1.Month >= 2 && a.Date1.Month <= 6)) .Count() > 0).ToList(); neizvineni = studentsNeizv.Count; } else { nothing = students.Where(s => s.Attendances.Where(a => a.Date1.Month >= 9 || a.Date1.Month == 1).Count() == 0).Count(); studentsNeizv = students.Where(s => s.Attendances .Where(a => (a.Att_type == 0 || a.Att_type == 1) && (a.Date1.Month >= 9 || a.Date1.Month == 1)) .Count() > 0).ToList(); neizvineni = studentsNeizv.Count; } x += 2; int header = x; newWorksheet.Range[newWorksheet.Cells[x, 1], newWorksheet.Cells[x, 2]].Merge(); newWorksheet.Cells[x, 1] = "Отсъствия"; newWorksheet.Range[newWorksheet.Cells[x, 1], newWorksheet.Cells[x, 2]].Font.Bold = true; x++; newWorksheet.Cells[x, 1] = "Без отсъствия"; newWorksheet.Cells[x, 2] = nothing.ToString(); x++; newWorksheet.Cells[x, 1] = "С неизвинени отсъствия"; newWorksheet.Cells[x, 2] = neizvineni.ToString(); x++; newWorksheet.Cells[x, 1] = "До 3 часа"; newWorksheet.Cells[x, 2] = studentsNeizv .Where(s => s.Attendances.Where(a => a.Att_type == 0).Count() + (s.Attendances.Where(a => a.Att_type == 1).Count() / 3) <= 3).Count(); x++; newWorksheet.Cells[x, 1] = "До 10 часа"; newWorksheet.Cells[x, 2] = studentsNeizv .Where(s => s.Attendances.Where(a => a.Att_type == 0).Count() + (s.Attendances.Where(a => a.Att_type == 1).Count() / 3) > 3 && s.Attendances.Where(a => a.Att_type == 0).Count() + (s.Attendances.Where(a => a.Att_type == 1).Count() / 3) <= 10).Count(); x++; newWorksheet.Cells[x, 1] = "До 15 часа"; newWorksheet.Cells[x, 2] = studentsNeizv .Where(s => s.Attendances.Where(a => a.Att_type == 0).Count() + (s.Attendances.Where(a => a.Att_type == 1).Count() / 3) > 10 && s.Attendances.Where(a => a.Att_type == 0).Count() + (s.Attendances.Where(a => a.Att_type == 1).Count() / 3) <= 15).Count(); x++; newWorksheet.Cells[x, 1] = "До 25 часа"; newWorksheet.Cells[x, 2] = studentsNeizv .Where(s => s.Attendances.Where(a => a.Att_type == 0).Count() + (s.Attendances.Where(a => a.Att_type == 1).Count() / 3) > 15 && s.Attendances.Where(a => a.Att_type == 0).Count() + (s.Attendances.Where(a => a.Att_type == 1).Count() / 3) <= 25).Count(); x++; newWorksheet.Cells[x, 1] = "До 10 часа"; newWorksheet.Cells[x, 2] = studentsNeizv .Where(s => s.Attendances.Where(a => a.Att_type == 0).Count() + (s.Attendances.Where(a => a.Att_type == 1).Count() / 3) > 25).Count(); newWorksheet.Range[newWorksheet.Cells[header, 1], newWorksheet.Cells[x, 2]].Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; //var att = AttendanceRepository.GetAttendanceBetweenDates(DateTime.Now.AddYears(-2), DateTime.Now.AddYears(2), class_id); //if (semester == 2) att = att.Where(a => a.Date1.Month >= 2 && a.Date1.Month <= 6).ToList(); //else att = att.Where(a => a.Date1.Month >= 9 || a.Date1.Month == 1).ToList(); }
public ActionResult GetAllStudents() { var result = repository.GetAllStudents(); return(View(result)); }
public ActionResult Show(int class_id = -1) { if (class_id == -1) { var classes = DB.GetClasses(); return(View(classes)); } else { var students = StudentsRepository.GetAllStudents(class_id); var subjects = DB.GetClassSubjects(class_id); string studClass = students[0].Class.Number.ToString(); if (students[0].Class.Letter == 1) { studClass += "a"; } else if (students[0].Class.Letter == 2) { studClass += "б"; } else if (students[0].Class.Letter == 3) { studClass += "в"; } else if (students[0].Class.Letter == 4) { studClass += "г"; } else if (students[0].Class.Letter == 5) { studClass += "д"; } var attendance = AttendanceRepository.CalculateClassAttendance(DateTime.Now.AddYears(-2), DateTime.Now.AddYears(2), class_id); var stats1 = StatsHelpers.GetSubjectsStats(21, class_id, false); var zipStats1 = StatsHelpers.GetSubjectsStats(21, class_id, true); var stats2 = StatsHelpers.GetSubjectsStats(23, class_id, false); var zipStats2 = StatsHelpers.GetSubjectsStats(23, class_id, true); StatsViewModel vm1 = new StatsViewModel() { AllSubjects = stats1, AllZipSubjects = zipStats1, Semester = 1 }; StatsViewModel vm2 = new StatsViewModel() { AllSubjects = stats2, AllZipSubjects = zipStats2, Semester = 3 }; AdminStatsViewModel vm = new AdminStatsViewModel() { Students = students, Subjects = subjects, SelectedClass = studClass, Attendance = attendance, Semester1 = vm1, Semester2 = vm2 }; return(View("ShowClass", vm)); } }
public List <StudentDTO> GetAllStudents() { return(_StudentsRepo.GetAllStudents()); }