public AcademicYearDetail Create(AcademicYearDetail academicYearToCreate)
 {
     var academicYearDetails = _context.AcademicYearDetails.Add(academicYearToCreate);
     _context.Entry(academicYearToCreate.Course).State = EntityState.Modified;
     _context.Entry(academicYearToCreate.Teacher).State = EntityState.Modified;
     _context.SaveChanges();
     return academicYearDetails;
 }
        public ActionResult Add(AcademicYearDetailsRegisterModel academicYearDetailsModel)
        {
            var academicYearDetails = new AcademicYearDetail
            {
                TeacherStartDate = ParseToHonduranDateTime.Parse(academicYearDetailsModel.TeacherStartDate),
                TeacherEndDate = ParseToHonduranDateTime.Parse(academicYearDetailsModel.TeacherEndDate),
                Schedule = ParseToHonduranDateTime.Parse(academicYearDetailsModel.Schedule),
                Room = academicYearDetailsModel.Room,
                Course = _courseRepository.GetById(academicYearDetailsModel.Course.Id),
                Teacher = _teacherRepository.GetById(academicYearDetailsModel.Teacher.Id),
                AcademicYear = _academicYearRepository.GetById(academicYearDetailsModel.AcademicYearId)
            };

            _academicYearDetailsRepository.Create(academicYearDetails);
            const string title = "Detalles de Año Académico Agregado";
            const string content = "El detalle del año académico ha sido agregado exitosamente.";
            _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage);
            return Redirect(string.Format("~/AcademicYearDetails/Index/{0}", academicYearDetailsModel.AcademicYearId));
        }
예제 #3
0
 public void CreateDefaultPensum(AcademicYear academicYear)
 {
     var pensums = GetDefaultPensum(academicYear.Grade.Id);
     var teacher = _context.Teachers.First(x => x.FirstName.Equals("Maestro"));
     foreach (var pensum in pensums)
     {
         var academicYearDetails = new AcademicYearDetail
         {
             TeacherStartDate = DateTime.Now,
             TeacherEndDate = DateTime.Now,
             Schedule = DateTime.Now,
             AcademicYear = academicYear,
             Course = pensum.Course,
             Teacher = teacher
         };
         _context.AcademicYearDetails.Add(academicYearDetails);
     }
     _context.SaveChanges();
 }
 public AcademicYearDetail Update(AcademicYearDetail itemToUpdate)
 {
     var updateCourse = false;
     var updateAcademicYear = false;
     var updateTeacher = false;
     var academicYearDetail = GetById(itemToUpdate.Id);
     academicYearDetail.TeacherStartDate = itemToUpdate.TeacherStartDate;
     academicYearDetail.TeacherEndDate = itemToUpdate.TeacherEndDate;
     academicYearDetail.Schedule = itemToUpdate.Schedule;
     academicYearDetail.Room = itemToUpdate.Room;
     if (academicYearDetail.AcademicYear.Id != itemToUpdate.AcademicYear.Id)
     {
         academicYearDetail.AcademicYear = itemToUpdate.AcademicYear;
         updateAcademicYear = true;
     }
     if (academicYearDetail.Course.Id != itemToUpdate.Course.Id)
     {
         academicYearDetail.Course = itemToUpdate.Course;
         updateCourse = true;
     }
     if (academicYearDetail.Teacher.Id != itemToUpdate.Teacher.Id)
     {
         academicYearDetail.Teacher = itemToUpdate.Teacher;
         updateTeacher = true;
     }
     return Update(academicYearDetail, updateAcademicYear, updateCourse, updateTeacher);
 }
 public AcademicYearDetail Update(AcademicYearDetail itemToUpdate, bool updateAcademicYear = true, bool updateCourse = true,
     bool updateTeacher = true)
 {
     if (updateAcademicYear)
         _context.Entry(itemToUpdate.AcademicYear).State = EntityState.Modified;
     if (updateCourse)
         _context.Entry(itemToUpdate.Course).State = EntityState.Modified;
     if (updateTeacher)
         _context.Entry(itemToUpdate.Teacher).State = EntityState.Modified;
     _context.SaveChanges();
     return itemToUpdate;
 }