public ActionResult Add(AcademicGradeRegisterModel model) { string title; string content; var toCreate = Mapper.Map <AcademicGrade>(model); var toCheck = _academicGradeRepository.Filter(x => x.Grade.Id == model.Grade && x.Section.Equals(model.Section)); if (toCheck.Any()) { title = "Error!"; content = "El Grado Académico ya existe."; _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.ErrorMessage); return(RedirectToAction("Index", new { yearId = model.AcademicYear })); } toCreate = _academicGradeRepository.Create(toCreate); foreach (var course in toCreate.ActivePensum.Courses) { var academicCourse = new AcademicCourse { AcademicGrade = toCreate, Course = course }; _academicCourseRepository.Create(academicCourse); } title = "Grado Académico Agregado"; content = "El Grado Académico " + toCreate.Grade.Name + " " + toCreate.Section + " ha sido guardado exitosamente."; _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage); return(RedirectToAction("Index", new { yearId = model.AcademicYear })); }
public ActionResult AutoGeneration(IEnumerable <NewAcademicYearGradeSpecModel> model, long yearId) { var year = _academicYearRepository.GetById(yearId); foreach (var newAcademicYeardGradeSpecModel in model) { char section = 'A'; var grade = _gradeRepository.GetById(newAcademicYeardGradeSpecModel.Grade); var pensum = _pensumRepository.GetById(newAcademicYeardGradeSpecModel.SelectedPensum); for (int i = 0; i < newAcademicYeardGradeSpecModel.Sections; i++) { var newGrade = new AcademicGrade { Grade = grade, AcademicYear = year, Section = section++ + "", ActivePensum = pensum }; newGrade = _academicGradeRepository.Create(newGrade); foreach (var course in newGrade.ActivePensum.Courses) { var academicCourse = new AcademicCourse { Course = course, AcademicGrade = newGrade }; academicCourse = _academicCourseRepository.Create(academicCourse); newGrade.CoursesDetails.Add(academicCourse); newGrade = _academicGradeRepository.Update(newGrade); } year.Grades.Add(newGrade); _academicYearRepository.Update(year); } } const string title = "Año Académico Agregado"; var content = "El año académico " + year.Year + " ha sido agregado exitosamente."; _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage); return(RedirectToAction("Index", "AcademicGrade", new { yearId })); }