Beispiel #1
0
        public JsonResult GetCustomers(string sidx, string sort, int page, int rows)
        {
            MCustomerContext context = new MCustomerContext();

            sort = (sort == null) ? "" : sort;
            int pageIndex = Convert.ToInt32(page) - 1;
            int pageSize  = rows;

            //var StudentList = context.MCustomers.Select(
            //        t => new
            //        {
            //            t.CustomerId,
            //            t.CustomerName
            //        });


            var customer = context.MCustomers.ToList();
            var order    = context.MOrders.ToList();
            var product  = context.MProducts.ToList();

            var viewModel = new CustomerViewModel
            {
                customers = new MCustomer(),
                orders    = order,
                products  = product
            };



            var innerJoinQuery =
                from category in categories
                join prod in products on category.ID equals prod.CategoryID
                select new { ProductName = prod.Name, Category = category.Name }; //produces flat sequence



            int totalRecords = StudentList.Count();
            var totalPages   = (int)Math.Ceiling((float)totalRecords / (float)rows);

            if (sort.ToUpper() == "DESC")
            {
                StudentList = StudentList.OrderByDescending(t => t.CustomerName);
                StudentList = StudentList.Skip(pageIndex * pageSize).Take(pageSize);
            }
            else
            {
                StudentList = StudentList.OrderBy(t => t.CustomerName);
                StudentList = StudentList.Skip(pageIndex * pageSize).Take(pageSize);
            }
            var jsonData = new
            {
                total = totalPages,
                page,
                records = totalRecords,
                rows    = StudentList
            };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }
        public void SortStudentListByGrades()
        {
            List <Student> SortedStudentList = new List <Student>();

            if (StudentList.Count() == 1)
            {
                SortedStudentList.Add(StudentList[0]);
            }
            if (StudentList.Count() == 2)
            {
                if (StudentList[0].ReturnStudentGrade() < StudentList[1].ReturnStudentGrade())
                {
                    SortedStudentList.Add(StudentList[0]);
                    SortedStudentList.Add(StudentList[1]);
                }
                if (StudentList[0].ReturnStudentGrade() > StudentList[1].ReturnStudentGrade())
                {
                    SortedStudentList.Add(StudentList[1]);
                    SortedStudentList.Add(StudentList[2]);
                }
            }
            if (StudentList.Count() > 2)
            {
                if (StudentList[0].ReturnStudentGrade() < StudentList[1].ReturnStudentGrade())
                {
                    SortedStudentList.Add(StudentList[0]);
                    SortedStudentList.Insert(1, StudentList[1]);
                }
                if (StudentList[0].ReturnStudentGrade() > StudentList[1].ReturnStudentGrade())
                {
                    SortedStudentList.Add(StudentList[1]);
                    SortedStudentList.Insert(1, StudentList[2]);
                }
                RemoveStudent(StudentList[0].ReturnID());
                RemoveStudent(StudentList[1].ReturnID());
                foreach (Student student in StudentList)
                {
                    if (student.ReturnStudentGrade() < SortedStudentList[0].ReturnStudentGrade())
                    {
                        SortedStudentList.Add(StudentList[0]);
                    }
                    for (int i = 0; i < SortedStudentList.Count() - 1; i++)
                    {
                        if (i < SortedStudentList.Count() - 2 && student.ReturnStudentGrade() > SortedStudentList[i].ReturnStudentGrade() && student.ReturnStudentGrade() < SortedStudentList[i + 1].ReturnStudentGrade())
                        {
                            SortedStudentList.Insert(i, student);
                        }
                        if (i == SortedStudentList.Count() - 1 && student.ReturnStudentGrade() > SortedStudentList[i].ReturnStudentGrade())
                        {
                            SortedStudentList.Add(student);
                        }
                    }
                }
            }
            StudentList = SortedStudentList;
        }
Beispiel #3
0
        public void LoadTest()
        {
            StudentList students = new StudentList();

            students.StudentListLoad();

            int expected = 14;
            int actual   = students.Count();

            Assert.AreEqual(expected, actual);
        }
        public decimal Median()
        {
            int middle = StudentList.Count() / 2;

            SortStudentListByGrades();
            if (StudentList.Count() % 2 == 1)
            {
                return(StudentList[middle].ReturnStudentGrade());
            }
            else
            {
                Console.WriteLine("There is an even number of students in this course, the median would be: ");
                return((StudentList[middle].ReturnStudentGrade() + StudentList[middle + 1].ReturnStudentGrade()) / 2);
            }
        }
Beispiel #5
0
        public double AverageGrade()
        {
            double averGradeSum = 0;
            double studCount    = StudentList.Count();

            foreach (var item in StudentList)
            {
                if (item.AverageGrade == 0)
                {
                    studCount--;
                }
                averGradeSum += item.AverageGrade;
            }

            return(averGradeSum / studCount);
        }
Beispiel #6
0
 public string StudentCounter()
 {
     return(StudentList.Count().ToString());
 }