Exemple #1
0
        public ActionResult Details(int id = 0)
        {
            SubjectGradesRecord subjectgradesrecord = _unitOfWork.SubjectGradesRecordRepository.GetById(id);

            if (subjectgradesrecord == null)
            {
                return(HttpNotFound());
            }
            return(View(subjectgradesrecord));
        }
Exemple #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            SubjectGradesRecord subjectgradesrecord = _unitOfWork.SubjectGradesRecordRepository.GetById(id);

            foreach (var grade in subjectgradesrecord.Grades.ToList())
            {
                _unitOfWork.GradeRepository.Delete(grade);
            }
            var registrationIdOfCurrentSubjectGradesRecord = subjectgradesrecord.Registration.Id;

            _unitOfWork.SubjectGradesRecordRepository.Delete(subjectgradesrecord);
            _unitOfWork.SubjectGradesRecordRepository.Save();
            return(RedirectToAction("Index", new { id = registrationIdOfCurrentSubjectGradesRecord }));
        }
Exemple #3
0
        /// <summary>
        /// Edits the SubjectGradesRecord with the specified id.
        /// </summary>
        /// <param name="id">The SubjectGradesRecord id.</param>
        /// <returns></returns>
        public ActionResult Edit(int id = 0)
        {
            SubjectGradesRecord subjectGradesRecord = _unitOfWork.SubjectGradesRecordRepository.GetById(id);

            if (subjectGradesRecord == null)
            {
                return(HttpNotFound());
            }

            int registrationId = subjectGradesRecord.Registration.Id;
            var levelIdOfCurrentRegistration = _unitOfWork.RegistrationRepository.GetById(registrationId).Degree.LevelId;

            var subjectGradesRecordViewModel = MapSubjectGradesRecord_To_SubjectGradesRecordViewModel(subjectGradesRecord);

            subjectGradesRecordViewModel.SubjectsList = new SelectList(_unitOfWork.SubjectRepository.GetAll().Where(s => s.LevelId == levelIdOfCurrentRegistration), "Id", "Name");
            subjectGradesRecordViewModel.PeriodsList  = _unitOfWork.PeriodRepository.GetAll().Where(p => p.LevelId == levelIdOfCurrentRegistration);

            return(View(subjectGradesRecordViewModel));
        }
Exemple #4
0
        private SubjectGradesRecord MapSubjectGradesRecordViewModel_To_SubjectGradesRecord(SubjectGradesRecordViewModel subjectGradesRecordViewModel)
        {
            var subjectGradesRecord = _unitOfWork.SubjectGradesRecordRepository.GetById(subjectGradesRecordViewModel.Id);

            // For editing existing grade record
            if (subjectGradesRecord != null)
            {
                subjectGradesRecord.SubjectId = subjectGradesRecordViewModel.SubjectId;

                foreach (var gradeViewModel in subjectGradesRecordViewModel.GradeViewModels)
                {
                    var grade = _unitOfWork.GradeRepository.GetById(gradeViewModel.Id);
                    grade.GradeValue = gradeViewModel.GradeValue;
                }
            }
            else // For creating new grade record
            {
                subjectGradesRecord = new SubjectGradesRecord
                {
                    Id           = subjectGradesRecordViewModel.Id,
                    Registration = _unitOfWork.RegistrationRepository.GetById(subjectGradesRecordViewModel.RegistrationId),
                    SubjectId    = subjectGradesRecordViewModel.SubjectId,
                    Grades       = new List <Grade>()
                };

                foreach (var grade in subjectGradesRecordViewModel.GradeViewModels)
                {
                    subjectGradesRecord.Grades.Add(new Grade
                    {
                        PeriodId   = grade.PeriodId,
                        GradeValue = grade.GradeValue
                    });
                }
            }

            return(subjectGradesRecord);
        }
Exemple #5
0
        private SubjectGradesRecordViewModel MapSubjectGradesRecord_To_SubjectGradesRecordViewModel(SubjectGradesRecord subjectGradesRecord)
        {
            var subjectGradesRecordViewModel = new SubjectGradesRecordViewModel()
            {
                RegistrationId  = subjectGradesRecord.Registration.Id,
                SubjectId       = subjectGradesRecord.Subject.Id,
                LevelId         = subjectGradesRecord.Registration.Degree.LevelId,
                StudentFullName = subjectGradesRecord.Registration.Student.FullName,
                GradeViewModels = new List <GradeViewModel>()
            };

            foreach (var grade in subjectGradesRecord.Grades)
            {
                subjectGradesRecordViewModel.GradeViewModels.Add(new GradeViewModel
                {
                    Id         = grade.Id,
                    PeriodId   = grade.PeriodId,
                    PeriodName = grade.Period.Name,
                    GradeValue = grade.GradeValue
                });
            }

            return(subjectGradesRecordViewModel);
        }