public void ExportSubjectListToExcel(int id)
        {
            StudentIndexVM model = new StudentIndexVM();
            GradeRepository gradeRepo = new GradeRepository();
            UserRepository<Student> studentRepo = new UserRepository<Student>();
            Student student = studentRepo.GetByID(id);

            model.Grades = gradeRepo.GetAll(filter: s => s.StudentID == id);

            var grid = new System.Web.UI.WebControls.GridView();

            var products = new System.Data.DataTable(student.FirstName);

            products.Columns.Add("Subject", typeof(string));
            products.Columns.Add("Grade", typeof(string));

            foreach (var item in model.Grades)
            {
                products.Rows.Add(item.Subject.Name, item.GradeValue);
            }

            grid.DataSource = products;
            grid.DataBind();

            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment; filename=" + student.FacultiNumber + ".xls");
            Response.ContentType = "application/excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            grid.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();
        }
        public ActionResult Index()
        {
            StudentIndexVM model = new StudentIndexVM();
            UserRepository<Student> stuRepo = new UserRepository<Student>();
            CourseRepository courseRepo = new CourseRepository();
            GradeRepository gradeRepo = new GradeRepository();
            UserRepository<Teacher> teacherRepo = new UserRepository<Teacher>();

            Student student = stuRepo.GetByID(Models.AuthenticationManager.LoggedUser.ID);

            model.FacultiNumber = student.FacultiNumber;
            model.FirstName = student.FirstName;
            model.LastName = student.LastName;

            Course course = courseRepo.GetAll(filter: x => x.CourseSubject.Any(c => c.Course.Student.Any(s => s.ID == Models.AuthenticationManager.LoggedUser.ID))).FirstOrDefault();

            model.CourseName = course.Name;

            model.Grades = gradeRepo.GetAll(filter: g => g.StudentID == Models.AuthenticationManager.LoggedUser.ID);

            return View(model);
        }
        public void ExportSubjectListToCSV(int id)
        {
            StudentIndexVM model = new StudentIndexVM();
            GradeRepository gradeRepo = new GradeRepository();
            UserRepository<Student> studentRepo = new UserRepository<Student>();

            model.Grades = gradeRepo.GetAll(filter: s => s.StudentID == id);
            Student student = studentRepo.GetByID(id);

            StringWriter sw = new StringWriter();

            sw.WriteLine("\"Subject\",\"Grade\"");

            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment;filename=" + student.FacultiNumber + ".csv");
            Response.ContentType = "text/csv";

            foreach (var item in model.Grades)
            {
                sw.WriteLine(string.Format("\"{0}\",\"{1}\"",
                                           item.Subject.Name,
                                           item.GradeValue));
            }

            Response.Write(sw.ToString());
            Response.End();
        }