示例#1
0
 public GradeController()
 {
     this.gradeRepository   = new GradeRepository(new GContext());
     this.studentRepository = new StudentRepository(new GContext());
     this.bookRespository   = new BookRepository(new GContext());
     this.chapterRepository = new ChapterRepository(new GContext());
 }
示例#2
0
        public ActionResult ShowGrades(int id, int courseSubjectID)
        {
            AdminControllerCourseSubjectVM courseSubjectModel = new AdminControllerCourseSubjectVM();
            GradeRepository gradeRepository = new GradeRepository();
            List <Grade>    studentGrades   = gradeRepository.GetAll(filter: s => s.Student.Id == id);


            Dictionary <string, List <Grade> > details = new Dictionary <string, List <Grade> >();
            List <string> subjectNameList = new List <string>();

            foreach (var item in studentGrades)
            {
                subjectNameList.Add(item.Subject.Name);
            }
            subjectNameList = subjectNameList.Distinct().ToList();

            foreach (var item in subjectNameList)
            {
                List <Grade> grades = new List <Grade>();
                grades = gradeRepository.GetAll(filter: s => s.Subject.Name == item && s.Student.Id == id);
                details.Add(item, grades);
            }

            courseSubjectModel.details = details;

            courseSubjectModel.StudentID = id;
            Student           student           = new Student();
            StudentRepository studentRepository = new StudentRepository();

            student = studentRepository.GetById(id);
            courseSubjectModel.StudentName     = student.FirstName + " " + student.LastName;
            courseSubjectModel.CourseSubjectID = courseSubjectID;
            return(View(courseSubjectModel));
        }
示例#3
0
 public GradeService(GradeRepository gradeRepository, ProfessorService professorService, AlunoService alunoService, MatriculaService matriculaService)
 {
     _gradeRepository  = gradeRepository;
     _professorService = professorService;
     _alunoService     = alunoService;
     _matriculaService = matriculaService;
 }
        public ActionResult ShowDetails(int id)
        {
            StudentControllerStudentVM model = new StudentControllerStudentVM();
            List<Grade> gradeList = new List<Grade>();
            GradeRepository gradeRepository = new GradeRepository();
            gradeList = gradeRepository.GetAll(filter: s => s.Student.Id == id);
            Dictionary<string, List<string>> details = new Dictionary<string, List<string>>();
            var subjectList = new List<string>();

            foreach (var item in gradeList)
            {
                subjectList.Add(item.Subject.Name);
            }
            subjectList = subjectList.Distinct().ToList();

            foreach (var item in subjectList)
            {
                var gradeValueList = new List<string>();
                List<Grade> grades = new List<Grade>();
                grades = gradeRepository.GetAll(filter: s => s.Subject.Name == item && s.Student.Id == id);
                foreach (var grade in grades)
                {
                    gradeValueList.Add(grade.GradeValue.ToString());
                }
                details.Add(item, gradeValueList);
            }
            model.SubjectGradeList = details;
            Student student = new Student();
            StudentRepository studentRepository = new StudentRepository();
            student = studentRepository.GetById(id);
            model.FirstName = student.FirstName;
            model.LastName = student.LastName;
            return View(model);
        }
 public DataTable StudentsGradesToExcel(Student student)
 {
     List<Grade> gradeList = new List<Grade>();
     GradeRepository gradeRepository = new GradeRepository();
     gradeList = gradeRepository.GetAll(filter: g => g.Student.Id == student.Id);
     var gradeTable = new DataTable("StudentsGrades");
     gradeTable.Columns.Add("SubjectName", typeof(string));
     gradeTable.Columns.Add("GradeValue", typeof(string));
     Dictionary<string, string> details = new Dictionary<string, string>();
     List<string> subjectNameList = new List<string>();
     List<string> gradeValues = new List<string>();
     foreach (var item in gradeList)
     {
         subjectNameList.Add(item.Subject.Name);
     }
     subjectNameList = subjectNameList.Distinct().ToList();
     foreach (var item in subjectNameList)
     {
         StringBuilder sb = new StringBuilder();
         List<Grade> grades = new List<Grade>();
         grades = gradeRepository.GetAll(filter: s => s.Subject.Name == item && s.Student.Id == student.Id);
         foreach (var grade in grades)
         {
             sb.Append(grade.GradeValue);
             sb.Append(",");
         }
         sb.Length -= 1;
         details.Add(item, sb.ToString());
     }
     foreach (var item in details)
     {
         gradeTable.Rows.Add(item.Key, item.Value);
     }
     return gradeTable;
 }
示例#6
0
 public PeriodGradeController()
 {
     _repository           = new PeriodGradeRepository();
     _userRepository       = new UserRoleRepository();
     _gradeGroupRepository = new GradeGroupRepository();
     _gradeRepository      = new GradeRepository();
 }
示例#7
0
        private void FillGradesCombo()
        {
            GradeRepository   gradeRepository = new GradeRepository();
            List <GradeModel> gradesList      = new List <GradeModel>();

            try
            {
                DataTable dataTable = gradeRepository.GetAllGrades();

                gradesList = TranslateDataTableToGradeModel(dataTable);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Network error...Please try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            this.cmbGrades.SelectedIndexChanged -= new EventHandler(cmbGrades_SelectedIndexChanged);

            BindingSource bs = new BindingSource();

            bs.DataSource = gradesList;

            cmbGrades.ValueMember   = "GradeID";
            cmbGrades.DisplayMember = "GradeName";
            cmbGrades.DataSource    = bs;

            cmbGrades.SelectedIndex = -1;

            this.cmbGrades.SelectedIndexChanged += new EventHandler(cmbGrades_SelectedIndexChanged);
        }
        public ActionResult AddGrade(GradeAddGradeVM model)
        {
            if (model.GradeValue < 2 || model.GradeValue > 6)
            {
                ModelState.AddModelError("Error", "Grade must be 2 - 6");
                return View(model);
            }

            GradeRepository gRepo = new GradeRepository();
            Grade grade = new Grade();
            var test = gRepo.GetAll(filter: g => g.StudentID == model.StudentID && g.SubjectID == model.SubjectID).FirstOrDefault();
            if (test != null)
            {
                ModelState.AddModelError("Error", "Student already have grade");
                return View(model);
            }

            grade.StudentID = model.StudentID;
            grade.SubjectID = model.SubjectID;
            grade.GradeValue = model.GradeValue;

            gRepo.Save(grade);

            return RedirectToAction("StudentsGrades" + "/" + model.SubjectID, "Grade");
        }
示例#9
0
 public StudentsController()
 {
     _studentRepository = new StudentRepository();
     _gradeRepository   = new GradeRepository();
     _groupRepository   = new GroupRepository();
     _majorRepository   = new MajorRepository();
     _accountRepository = new AccountRepository();
 }
示例#10
0
        public void Setup()
        {
            //setup the connection and context
            SetupConnectionAndContext();

            //setup the grade repository
            gradeRepository   = new GradeRepository(Context);
            studentRepository = new StudentRepository(Context);
            courseRepository  = new CourseRepository(Context);
        }
 public JsonResult DeleteGrade(int gradeId)
 {
     Grade grade = new Grade();
     UnitOfWork unitOfWork = new UnitOfWork();
     GradeRepository gradeRepository = new GradeRepository();
     grade = gradeRepository.GetById(gradeId);
     gradeRepository.Delete(grade);
     unitOfWork.Commit();
     return Json("successfully deleted", JsonRequestBehavior.AllowGet);
 }
示例#12
0
 public UnitOfWork(DatabaseContext databaseContext)
 {
     _databaseContext = databaseContext;
     Courses          = new CourseRepository(_databaseContext);
     Exams            = new ExamRepository(_databaseContext);
     Grades           = new GradeRepository(_databaseContext);
     Questions        = new QuestionRepository(_databaseContext);
     Students         = new StudentRepository(_databaseContext);
     Teachers         = new TeacherRepository(_databaseContext);
     Answers          = new AnswerRepository(_databaseContext);
 }
示例#13
0
        public async Task AverageAsync_Student_CalculatesAverageCorrectly()
        {
            using var context = new UniversityContext(builder.Options);
            var repository = new GradeRepository(context);
            // From UniversityContext OnModelCreating
            var initialNumber = 3;

            var count = await repository.AverageAsync(grade => grade.StudentId == 3, grade => grade.Mark);

            Assert.That(count, Is.EqualTo(initialNumber));
        }
示例#14
0
        public async Task CountExpressionsAsync_Grades_CountsCorrectly()
        {
            using var context = new UniversityContext(builder.Options);
            var repository = new GradeRepository(context);
            // From UniversityContext OnModelCreating
            var initialNumber = 2;

            var count = await repository.CountAsync(grade => grade.StudentId == 3);

            Assert.That(count, Is.EqualTo(initialNumber));
        }
        public JsonResult DeleteGrade(int gradeId)
        {
            Grade           grade           = new Grade();
            UnitOfWork      unitOfWork      = new UnitOfWork();
            GradeRepository gradeRepository = new GradeRepository();

            grade = gradeRepository.GetById(gradeId);
            gradeRepository.Delete(grade);
            unitOfWork.Commit();
            return(Json("successfully deleted", JsonRequestBehavior.AllowGet));
        }
示例#16
0
 public StudentController()
 {
     _repository                        = new PeriodGradeStudentRepository();
     _periodRepository                  = new PeriodRepository();
     _gradeRepository                   = new GradeRepository();
     _genderRepository                  = new GenderRepository();
     _studentRepository                 = new StudentRepository();
     _transactionTypeRepository         = new TransactionTypeRepository();
     _periodGradeStudentRepository      = new PeriodGradeStudentRepository();
     _studentPayConfigurationRepository = new StudentPayConfigurationRepository();
     _cityRepository                    = new CityRepository();
 }
        public ActionResult StudentDetails(int StudentID)
        {
            if (!AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
            {
                return(RedirectToAction("Default", "Login"));
            }
            List <Grade>      studentGrades     = new List <Grade>();
            GradeRepository   gradeRepository   = new GradeRepository();
            Student           student           = new Student();
            StudentRepository studentRepository = new StudentRepository();

            student = studentRepository.GetById(StudentID);
            TeacherControllerStudentsVM model = new TeacherControllerStudentsVM();

            studentGrades = gradeRepository.GetAll(filter: g => g.Student.Id == StudentID);

            model.FirstName      = student.FirstName;
            model.LastName       = student.LastName;
            model.FaculityNumber = student.FacultyNumber;
            model.Course         = student.Course.Name;
            model.StudentID      = student.Id;
            model.CourseID       = student.Course.Id;

            Dictionary <string, List <Grade> > details = new Dictionary <string, List <Grade> >();
            List <string> subjectNameList = new List <string>();

            foreach (var item in studentGrades)
            {
                subjectNameList.Add(item.Subject.Name);
            }
            subjectNameList = subjectNameList.Distinct().ToList();

            foreach (var item in subjectNameList)
            {
                List <Grade> grades = new List <Grade>();
                grades = gradeRepository.GetAll(filter: s => s.Subject.Name == item && s.Student.Id == StudentID);
                details.Add(item, grades);
            }
            model.SubjectGradeList = details;

            List <Subject>          subjects          = new List <Subject>();
            CourseSubjectRepository courseSubjectRepo = new CourseSubjectRepository();
            List <CourseSubject>    courseSubjectList = new List <CourseSubject>();

            courseSubjectList = courseSubjectRepo.GetAll(filter: c => c.CourseID == student.CourseID);
            foreach (var item in courseSubjectList)
            {
                subjects.Add(item.Subject);
            }
            model.SubjectList = subjects;
            return(View(model));
        }
        public JsonResult GetGrade(int gradeId)
        {
            Grade           grade           = new Grade();
            GradeRepository gradeRepository = new GradeRepository();

            grade = gradeRepository.GetById(gradeId);
            SelectListItem gradeItem = new SelectListItem()
            {
                Text = grade.GradeValue.ToString(), Value = grade.Id.ToString(),
            };

            return(Json(gradeItem, JsonRequestBehavior.AllowGet));
        }
示例#19
0
        private void FillGradesCombo(long gradeID)
        {
            GradeRepository   gradeRepository = new GradeRepository();
            List <GradeModel> gradeModels     = new List <GradeModel>();
            DataTable         dataTable       = new DataTable();

            try
            {
                dataTable = gradeRepository.GetAllGrades();

                gradeModels = TranslateDataTableToGradeModel(dataTable);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Network error...Please try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                dataTable.Clear();
                dataTable = null;
            }

            this.cmbGrades.SelectedIndexChanged -= new EventHandler(cmbGrades_SelectedIndexChanged);

            BindingSource bs = new BindingSource();

            bs.DataSource = gradeModels;

            cmbGrades.ValueMember   = "GradeID";
            cmbGrades.DisplayMember = "GradeName";
            cmbGrades.DataSource    = bs;

            if (gradeID > 0)
            {
                cmbGrades.SelectedValue = gradeID;
            }
            else
            {
                cmbGrades.SelectedIndex = -1;
            }

            this.cmbGrades.SelectedIndexChanged += new EventHandler(cmbGrades_SelectedIndexChanged);

            if (_lessonPlannerID > 0)
            {
                cmbGrades.Enabled = false;
            }
        }
        public JsonResult AddGradeToStudent(int gradevalue, int studentid, int subjectid)
        {
            GradeRepository gradeRepo = new GradeRepository();
            Grade grade = gradeRepo.GetAll(filter: g => g.StudentID == studentid && g.SubjectID == subjectid).FirstOrDefault();

            if (grade == null)
            {
                grade = new Grade();
                grade.StudentID = studentid;
                grade.GradeValue = gradevalue;
                grade.SubjectID = subjectid;

                gradeRepo.Save(grade);
                return Json(true);
            }
            return Json(false);
        }
        public DataTable SubjectGrades(Subject subject)
        {
            List <Grade>    gradeList       = new List <Grade>();
            GradeRepository gradeRepository = new GradeRepository();

            gradeList = gradeRepository.GetAll(filter: s => s.Subject.Id == subject.Id);
            StudentRepository studentRepository = new StudentRepository();
            var gradeTable = new DataTable("SubjectsGrades");

            gradeTable.Columns.Add("StudentName", typeof(string));
            gradeTable.Columns.Add("GradeValue", typeof(string));
            Dictionary <string, string> details = new Dictionary <string, string>();
            List <string> gradeValues           = new List <string>();
            List <int>    studentList           = new List <int>();

            foreach (var item in gradeList)
            {
                studentList.Add(item.Student.Id);
            }
            studentList = studentList.Distinct().ToList();
            foreach (var item in studentList)
            {
                StringBuilder sb     = new StringBuilder();
                List <Grade>  grades = new List <Grade>();
                grades = gradeRepository.GetAll(filter: s => s.Student.Id == item && s.Subject.Id == subject.Id);
                foreach (var grade in grades)
                {
                    sb.Append(grade.GradeValue);
                    sb.Append(",");
                }
                sb.Length -= 1;
                Student student = new Student();
                student = studentRepository.GetAll(filter: s => s.Id == item).FirstOrDefault();
                string fullName = student.FirstName + " " + student.LastName;
                details.Add(fullName, sb.ToString());
            }

            foreach (var item in details)
            {
                gradeTable.Rows.Add(item.Key, item.Value);
            }
            return(gradeTable);
        }
        public ActionResult AddGrade(int studentID, int subjectID)
        {
            GradeAddGradeVM model = new GradeAddGradeVM();

            UserRepository<Student> sRepo = new UserRepository<Student>();
            SubjectRepository subjRepo = new SubjectRepository();
            GradeRepository gRepo = new GradeRepository();

            Student student = sRepo.GetAll(filter: s => s.ID == studentID && s.Course.CourseSubject.Any(sub => sub.SubjectID == subjectID)).FirstOrDefault();

            Subject subject = subjRepo.GetByID(subjectID);

            Grade grade = gRepo.GetAll(filter: g => g.StudentID == student.ID).FirstOrDefault();

            model.StudentID = student.ID;
            model.SubjectID = subject.ID;

            return View(model);
        }
        public DataTable SubjectGrades(Subject subject)
        {
            List<Grade> gradeList = new List<Grade>();
            GradeRepository gradeRepository = new GradeRepository();
            gradeList = gradeRepository.GetAll(filter: s => s.Subject.Id == subject.Id);
            StudentRepository studentRepository = new StudentRepository();
            var gradeTable = new DataTable("SubjectsGrades");
            gradeTable.Columns.Add("StudentName",typeof(string));
            gradeTable.Columns.Add("GradeValue", typeof(string));
            Dictionary<string, string> details = new Dictionary<string, string>();
            List<string> gradeValues = new List<string>();
            List<int> studentList = new List<int>();
            foreach (var item in gradeList)
            {
                studentList.Add(item.Student.Id);
            }
            studentList = studentList.Distinct().ToList();
            foreach (var item in studentList)
            {
                StringBuilder sb = new StringBuilder();
                List<Grade> grades = new List<Grade>();
                grades = gradeRepository.GetAll(filter: s => s.Student.Id == item && s.Subject.Id == subject.Id);
                foreach (var grade in grades)
                {
                    sb.Append(grade.GradeValue);
                    sb.Append(",");
                }
                sb.Length -= 1;
                Student student = new Student();
                student = studentRepository.GetAll(filter: s=> s.Id == item).FirstOrDefault();
                string fullName = student.FirstName + " " + student.LastName;
                details.Add(fullName, sb.ToString());
            }

            foreach (var item in details)
            {
                gradeTable.Rows.Add(item.Key, item.Value);
            }
            return gradeTable;
        }
        public DataTable StudentsGradesToExcel(Student student)
        {
            List <Grade>    gradeList       = new List <Grade>();
            GradeRepository gradeRepository = new GradeRepository();

            gradeList = gradeRepository.GetAll(filter: g => g.Student.Id == student.Id);
            var gradeTable = new DataTable("StudentsGrades");

            gradeTable.Columns.Add("SubjectName", typeof(string));
            gradeTable.Columns.Add("GradeValue", typeof(string));
            Dictionary <string, string> details = new Dictionary <string, string>();
            List <string> subjectNameList       = new List <string>();
            List <string> gradeValues           = new List <string>();

            foreach (var item in gradeList)
            {
                subjectNameList.Add(item.Subject.Name);
            }
            subjectNameList = subjectNameList.Distinct().ToList();
            foreach (var item in subjectNameList)
            {
                StringBuilder sb     = new StringBuilder();
                List <Grade>  grades = new List <Grade>();
                grades = gradeRepository.GetAll(filter: s => s.Subject.Name == item && s.Student.Id == student.Id);
                foreach (var grade in grades)
                {
                    sb.Append(grade.GradeValue);
                    sb.Append(",");
                }
                sb.Length -= 1;
                details.Add(item, sb.ToString());
            }
            foreach (var item in details)
            {
                gradeTable.Rows.Add(item.Key, item.Value);
            }
            return(gradeTable);
        }
        public ActionResult ShowDetails(int id)
        {
            StudentControllerStudentVM model = new StudentControllerStudentVM();
            List <Grade>    gradeList        = new List <Grade>();
            GradeRepository gradeRepository  = new GradeRepository();

            gradeList = gradeRepository.GetAll(filter: s => s.Student.Id == id);
            Dictionary <string, List <string> > details = new Dictionary <string, List <string> >();
            var subjectList = new List <string>();

            foreach (var item in gradeList)
            {
                subjectList.Add(item.Subject.Name);
            }
            subjectList = subjectList.Distinct().ToList();


            foreach (var item in subjectList)
            {
                var          gradeValueList = new List <string>();
                List <Grade> grades         = new List <Grade>();
                grades = gradeRepository.GetAll(filter: s => s.Subject.Name == item && s.Student.Id == id);
                foreach (var grade in grades)
                {
                    gradeValueList.Add(grade.GradeValue.ToString());
                }
                details.Add(item, gradeValueList);
            }
            model.SubjectGradeList = details;
            Student           student           = new Student();
            StudentRepository studentRepository = new StudentRepository();

            student         = studentRepository.GetById(id);
            model.FirstName = student.FirstName;
            model.LastName  = student.LastName;
            return(View(model));
        }
        public JsonResult EditGrade(int gradeId, double gradeValue, int subjectId, int studentId)
        {
            Grade           grade     = new Grade();
            GradeRepository gradeRepo = new GradeRepository();
            SelectListItem  gradeItem = null;

            if (gradeId != 0)
            {
                grade            = gradeRepo.GetById(gradeId);
                gradeValue       = System.Math.Round(gradeValue, 2);
                grade.GradeValue = gradeValue;
                gradeRepo.Save(grade);
            }
            else
            {
                UnitOfWork        unitOfWork        = new UnitOfWork();
                StudentRepository studentRepository = new StudentRepository(unitOfWork);
                GradeRepository   gradeRepository   = new GradeRepository(unitOfWork);
                SubjectRepository subjectRepository = new SubjectRepository(unitOfWork);
                Student           student           = new Student();
                student = studentRepository.GetById(studentId);
                Subject subject = new Subject();
                subject          = subjectRepository.GetById(subjectId);
                grade.SubjectID  = subjectId;
                grade.Subject    = subject;
                grade.Student    = student;
                gradeValue       = System.Math.Round(gradeValue, 2);
                grade.GradeValue = gradeValue;
                gradeRepository.Save(grade);
                unitOfWork.Commit();
            }
            gradeItem = new SelectListItem()
            {
                Text = grade.GradeValue.ToString(), Value = grade.Id.ToString()
            };
            return(Json(gradeItem, JsonRequestBehavior.AllowGet));
        }
示例#27
0
        // ReSharper disable once UnusedMember.Global
        public void Delete(LessonDeleteRequest request)
        {
            Guard.IsTrue(lessonId => 0 < lessonId, request.LessonId);
            Guard.AgainstEmpty(request.Provider);
            Guard.AgainstEmpty(request.ProviderId);
            var existingUser = UserHelpers.GetExistingUser(request, UserRepository);

            Guard.IsTrue(eu => eu.IsNew == false, existingUser);

            Guard.AgainstEmpty(request.StudentProvider);
            Guard.AgainstEmpty(request.StudentProviderId);
            var existingStudent = UserHelpers.GetExistingUser(new LessonDeleteRequest {
                Provider = request.StudentProvider, ProviderId = request.StudentProviderId
            }, UserRepository);

            Guard.IsTrue(eu => eu.IsNew == false, existingStudent);
            Guard.IsTrue(es => es.IsStudent, existingStudent);

            var grade = GradeRepository.GetGrade(request.LessonId, request.StudentProvider, request.ProviderId);

            if (grade == null)
            {
                return;
            }

            if (existingUser.IsTeacher == false || request.Provider != grade.TeacherProvider || request.ProviderId != grade.TeacherProviderId)
            {
                throw new HttpError(HttpStatusCode.Unauthorized, "Unauthorized");
            }

            if (grade.IsDeleted)
            {
                return;
            }

            GradeRepository.DeleteGrade(grade.Id);
        }
        public void ExportSubjectListToCSV(int id)
        {
            GradeStudentsGradesVM model = new GradeStudentsGradesVM();
            GradeRepository gradeRepo = new GradeRepository();
            SubjectRepository subjRepo = new SubjectRepository();
            UserRepository<Student> studentRepo = new UserRepository<Student>();

            List<Student> students = studentRepo.GetAll(filter: s => s.Course.CourseSubject.Any(t => t.SubjectID == id));
            List<Grade> grades = gradeRepo.GetAll(filter: s => s.SubjectID == id);
            Subject  subject = subjRepo.GetByID(id);

            StringWriter sw = new StringWriter();

            sw.WriteLine("\"Faculty number\",\"First name\",\"Last name\",\"Grade\"");

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

            foreach (var student in students)
            {
                string grade = student.Grades.Select(x => x.GradeValue).FirstOrDefault().ToString();
                grade = grade == "0" ? "" : grade;
                sw.WriteLine(string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\"",
                                           student.FacultiNumber,
                                           student.FirstName,
                                           student.LastName,
                                           grade));
            }

            Response.Write(sw.ToString());

            Response.End();
        }
示例#29
0
        // ReSharper disable once UnusedMember.Global
        public void Post(GradeUpsertRequest request)
        {
            Guard.IsTrue(lessonId => 0 < lessonId, request.LessonId);
            Guard.AgainstEmpty(request.Provider);
            Guard.AgainstEmpty(request.ProviderId);
            var existingUser = UserHelpers.GetExistingUser(request, UserRepository);

            Guard.IsTrue(eu => eu.IsNew == false, existingUser);

            Guard.AgainstEmpty(request.StudentProvider);
            Guard.AgainstEmpty(request.StudentProviderId);
            var existingStudent = UserHelpers.GetExistingUser(new LessonDeleteRequest {
                Provider = request.StudentProvider, ProviderId = request.StudentProviderId
            }, UserRepository);

            Guard.IsTrue(eu => eu.IsNew == false, existingStudent);
            Guard.IsTrue(es => es.IsStudent, existingStudent);

            var lesson = LessonRepository.Find(request.LessonId);

            if (lesson == null || lesson.IsDeleted)
            {
                throw new HttpError(HttpStatusCode.NotFound, "NotFound");
            }

            if (request.Provider != lesson.Provider || request.ProviderId != lesson.ProviderId)
            {
                throw new HttpError(HttpStatusCode.Unauthorized, "Unauthorized");
            }

            var grade = GradeRepository.GetGrade(request.LessonId, request.StudentProvider, request.ProviderId);

            if (grade == null)
            {
                grade = new GradeModel
                {
                    LessonId          = request.LessonId,
                    StudentProvider   = request.StudentProvider,
                    StudentProviderId = request.StudentProviderId,
                    TeacherProvider   = request.Provider,
                    TeacherProviderId = request.ProviderId,
                    Grade             = request.Grade,
                    Comments          = request.Comments
                };

                GradeRepository.Add(grade);
            }
            else
            {
                grade.LessonId          = request.LessonId;
                grade.StudentProvider   = request.StudentProvider;
                grade.StudentProviderId = request.StudentProviderId;
                grade.TeacherProvider   = request.Provider;
                grade.TeacherProviderId = request.ProviderId;
                grade.Grade             = request.Grade;
                grade.Comments          = request.Comments;
                grade.UpdateDateUtc     = DateTime.UtcNow;

                GradeRepository.Update(grade);
            }
        }
        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 StudentsGrades(int id)
        {
            GradeStudentsGradesVM model = new GradeStudentsGradesVM();
            GradeRepository gradeRepo = new GradeRepository();
            SubjectRepository subjRepo = new SubjectRepository();
            UserRepository<Student> studentRepo = new UserRepository<Student>();

            model.Students = studentRepo.GetAll(filter: s => s.Course.CourseSubject.Any(t => t.SubjectID == id));

            Subject subject = subjRepo.GetByID(id);

            model.SubjectID = subject.ID;

            return View(model);
        }
        public void ExportSubjectListToExcel(int id)
        {
            GradeStudentsGradesVM model = new GradeStudentsGradesVM();
            GradeRepository gradeRepo = new GradeRepository();
            SubjectRepository subjRepo = new SubjectRepository();
            UserRepository<Student> studentRepo = new UserRepository<Student>();

            List<Student> students = studentRepo.GetAll(filter: s => s.Course.CourseSubject.Any(t => t.SubjectID == id));
            List<Grade> grades = gradeRepo.GetAll(filter: s => s.SubjectID == id);

            Subject subject = subjRepo.GetByID(id);

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

            var products = new System.Data.DataTable(subject.Name);

            products.Columns.Add("FacultiNumber", typeof(string));
            products.Columns.Add("FirstName", typeof(string));
            products.Columns.Add("LastName", typeof(string));
            products.Columns.Add("Grade", typeof(string));
            foreach (var student in students)
            {
                string grade = student.Grades.Select(x => x.GradeValue).FirstOrDefault().ToString();
                grade = grade == "0" ? "" : grade;
                products.Rows.Add(student.FacultiNumber, student.FirstName, student.LastName, grade);
            }

            grid.DataSource = products;
            // grid.DataSource = model.Students;

            grid.DataBind();

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

            grid.RenderControl(htw);

            Response.Write(sw.ToString());

            Response.End();
        }
示例#33
0
 public GradeBL()
 {
     _gradeObj = new GradeRepository();
 }
示例#34
0
 public GradesController()
 {
     _gradeRepository = new GradeRepository();
 }
        public ActionResult ShowGrades(int id, int courseSubjectID)
        {
            AdminControllerCourseSubjectVM courseSubjectModel = new AdminControllerCourseSubjectVM();
            GradeRepository gradeRepository = new GradeRepository();
            List<Grade> studentGrades = gradeRepository.GetAll(filter: s => s.Student.Id == id);

            Dictionary<string, List<Grade>> details = new Dictionary<string, List<Grade>>();
            List<string> subjectNameList = new List<string>();

            foreach (var item in studentGrades)
            {
                subjectNameList.Add(item.Subject.Name);
            }
            subjectNameList = subjectNameList.Distinct().ToList();

            foreach (var item in subjectNameList)
            {
                List<Grade> grades = new List<Grade>();
                grades = gradeRepository.GetAll(filter: s => s.Subject.Name == item && s.Student.Id == id);
                details.Add(item, grades);
            }

            courseSubjectModel.details = details;

            courseSubjectModel.StudentID = id;
            Student student = new Student();
            StudentRepository studentRepository = new StudentRepository();
            student = studentRepository.GetById(id);
            courseSubjectModel.StudentName = student.FirstName + " " + student.LastName;
            courseSubjectModel.CourseSubjectID = courseSubjectID;
            return View(courseSubjectModel);
        }
 public JsonResult EditGrade(int gradeId, double gradeValue, int subjectId, int studentId)
 {
     Grade grade = new Grade();
     GradeRepository gradeRepo = new GradeRepository();
     SelectListItem gradeItem = null;
     if (gradeId != 0)
     {
         grade = gradeRepo.GetById(gradeId);
         gradeValue = System.Math.Round(gradeValue, 2);
         grade.GradeValue = gradeValue;
         gradeRepo.Save(grade);
     }
     else
     {
         UnitOfWork unitOfWork = new UnitOfWork();
         StudentRepository studentRepository = new StudentRepository(unitOfWork);
         GradeRepository gradeRepository = new GradeRepository(unitOfWork);
         SubjectRepository subjectRepository = new SubjectRepository(unitOfWork);
         Student student = new Student();
         student = studentRepository.GetById(studentId);
         Subject subject = new Subject();
         subject = subjectRepository.GetById(subjectId);
         grade.SubjectID = subjectId;
         grade.Subject = subject;
         grade.Student = student;
         gradeValue = System.Math.Round(gradeValue, 2);
         grade.GradeValue = gradeValue;
         gradeRepository.Save(grade);
         unitOfWork.Commit();
     }
     gradeItem = new SelectListItem() { Text = grade.GradeValue.ToString(), Value = grade.Id.ToString() };
     return Json(gradeItem, JsonRequestBehavior.AllowGet);
 }
        public void GetGrades_StudentFound_ReturnsGrades()
        {
            //create the new student
            var newStudent = new Student()
            {
                FirstName = "Mikesh",
                LastName  = "Mistry"
            };

            //add the student to the database
            studentRepository.Add(newStudent);

            //add some courses
            var courseRepository = new CourseRepository(Context);

            var courseList = new List <Course>();

            // add a list of courses
            courseList.Add(new Course {
                Name = "Introduction to C#", Description = "Introduces students to C# programming"
            });
            courseList.Add(new Course {
                Name = "Introduction to Java", Description = "Introduces students to Java programming"
            });

            //add the course using add range
            courseRepository.AddRange(courseList);

            //use the find method to find a student
            var foundstudent = studentRepository.Find(student => student.FirstName == "Mikesh" && student.LastName == "Mistry").FirstOrDefault();



            //found the student
            if (foundstudent != null)
            {
                //enroll the student into the two course
                foreach (var course in courseList)
                {
                    courseRepository.EnrollStudentIntoCourse(foundstudent.StudentId, course.CourseId);
                }


                //get the found student
                var studentCourseList = studentRepository.GetId(foundstudent.StudentId);

                if (studentCourseList != null)
                {
                    //check to see if the grade was added
                    var gradeAdded = false;

                    //assign a student a grade
                    var gradeRepository = new GradeRepository(Context);

                    foreach (var course in studentCourseList.Courses)
                    {
                        gradeAdded = gradeRepository.AssignGradeToStudent(studentCourseList.StudentId, course.CourseId, "A+");
                        Assert.IsTrue(gradeAdded);
                    }


                    Assert.AreEqual(2, studentCourseList.Grades.Count());
                }
            }
        }
        public ActionResult StudentDetails(int StudentID)
        {
            if (!AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
            {
                return RedirectToAction("Default", "Login");
            }
            List<Grade> studentGrades = new List<Grade>();
            GradeRepository gradeRepository = new GradeRepository();
            Student student = new Student();
            StudentRepository studentRepository = new StudentRepository();
            student = studentRepository.GetById(StudentID);
            TeacherControllerStudentsVM model = new TeacherControllerStudentsVM();
            studentGrades = gradeRepository.GetAll(filter: g => g.Student.Id == StudentID);

            model.FirstName = student.FirstName;
            model.LastName = student.LastName;
            model.FaculityNumber = student.FacultyNumber;
            model.Course = student.Course.Name;
            model.StudentID = student.Id;
            model.CourseID = student.Course.Id;

            Dictionary<string, List<Grade>> details = new Dictionary<string, List<Grade>>();
            List<string> subjectNameList = new List<string>();

            foreach (var item in studentGrades)
            {
                subjectNameList.Add(item.Subject.Name);
            }
            subjectNameList = subjectNameList.Distinct().ToList();

            foreach (var item in subjectNameList)
            {
                List<Grade> grades = new List<Grade>();
                grades = gradeRepository.GetAll(filter: s => s.Subject.Name == item && s.Student.Id == StudentID);
                details.Add(item, grades);
            }
            model.SubjectGradeList = details;

            List<Subject> subjects = new List<Subject>();
            CourseSubjectRepository courseSubjectRepo = new CourseSubjectRepository();
            List<CourseSubject> courseSubjectList = new List<CourseSubject>();
            courseSubjectList = courseSubjectRepo.GetAll(filter: c => c.CourseID == student.CourseID);
            foreach (var item in courseSubjectList)
            {
                subjects.Add(item.Subject);
            }
            model.SubjectList = subjects;
            return View(model);
        }
 public JsonResult GetGrade(int gradeId)
 {
     Grade grade = new Grade();
     GradeRepository gradeRepository = new GradeRepository();
     grade = gradeRepository.GetById(gradeId);
     SelectListItem gradeItem = new SelectListItem() { Text = grade.GradeValue.ToString(), Value = grade.Id.ToString(), };
     return Json(gradeItem, JsonRequestBehavior.AllowGet);
 }
示例#40
0
 public GradeRepository()
 {
     _repo = new GradeRepository();
 }
示例#41
0
 public GradeController(ApplicationDbContext context)
 {
     _gradeRepository = new GradeRepository(context);
 }
示例#42
0
 public GradeLogic()
 {
     _gradeRepository = new GradeRepository();
 }
        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();
        }
示例#44
0
 public HomeController()
 {
     this.gradeRepository = new GradeRepository(new GContext());
 }
示例#45
0
        // ReSharper disable once UnusedMember.Global
        public IEnumerable <GroupedStudentLessonAnswerResponse> Post(StudentLessonAnswerGetAllRequest request)
        {
            Guard.AgainstEmpty(request.Provider);
            Guard.AgainstEmpty(request.ProviderId);
            var existingUser = UserHelpers.GetExistingUser(request, UserRepository);

            Guard.IsTrue(eu => eu.IsNew == false, existingUser);
            Guard.GreaterThan(0, request.LessonId, "LessonId");
            Guard.IsTrue(eu => eu.IsTeacher, existingUser);

            var lesson = LessonRepository.Find(request.LessonId);

            if (request.Provider != lesson.Provider || request.ProviderId != lesson.ProviderId)
            {
                throw new HttpError(HttpStatusCode.Unauthorized, "Unauthorized");
            }

            var studentLessonAnswers        = StudentLessonAnswerRepository.GetAllByLessonId(request.LessonId);
            var groupedStudentLessonAnswers = studentLessonAnswers.GroupBy(g => new { g.Provider, g.ProviderId }).ToList();
            var allStudents = groupedStudentLessonAnswers.Select(g => UserRepository.GetUserByProviderAndProviderId(g.Key.Provider, g.Key.ProviderId)).ToList();

            var response = new List <GroupedStudentLessonAnswerResponse>();

            foreach (var grouping in groupedStudentLessonAnswers)
            {
                var student = allStudents.SingleOrDefault(a => a.Provider == grouping.Key.Provider && a.ProviderId == grouping.Key.ProviderId);
                if (student == null || student.IsStudent == false)
                {
                    ErrorLogRepository.Add(new ErrorLog
                    {
                        Application = "MetacognitiveTutor.Api",
                        Message     = $"No student found for Provider '{grouping.Key.Provider}', ProviderId '{grouping.Key.ProviderId}'; LessonId: '{request.LessonId}'.",
                        Provider    = request.Provider,
                        ProviderId  = request.ProviderId,
                    });
                    continue;
                }

                var grade = GradeRepository.GetGrade(request.LessonId, student.Provider, student.ProviderId);
                response.Add(new GroupedStudentLessonAnswerResponse
                {
                    LessonId             = request.LessonId,
                    BookTitle            = lesson.BookTitle,
                    Name                 = student.Name,
                    Provider             = student.Provider,
                    ProviderId           = student.ProviderId,
                    ProviderPic          = student.ProviderPic,
                    StudentLessonAnswers = grouping.Select(g => new StudentLessonAnswerResponse
                    {
                        Id           = g.Id,
                        LessonId     = g.LessonId,
                        QuestionType = g.QuestionType,
                        QuestionId   = g.QuestionId,
                        Question     = g.Question,
                        Answer       = g.Answer
                    }).OrderByDescending(sla => sla.QuestionType.Equals("card_pyramid", StringComparison.OrdinalIgnoreCase)).ThenByDescending(sla => sla.QuestionType.Equals("word_scramble", StringComparison.OrdinalIgnoreCase)),
                    GradeResponse = grade == null ? new GradeResponse {
                        IsGraded = false
                    } : new GradeResponse {
                        IsGraded = true, Comments = grade.Comments, Grade = grade.Grade
                    }
                });
            }

            return(response);
        }
示例#46
0
 public GraphicController()
 {
     _gradeRepository  = new GradeRepository();
     _periodRepository = new PeriodRepository();
 }
        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);
        }