public ActionResult Add(EnrollRegisterModel modelEnroll) { Student student = _studentRepository.GetById(modelEnroll.Id); List<AcademicYear> collection = _academicYearRepository.Filter(x => x.Grade.Id == modelEnroll.GradeId && x.Section.Equals(modelEnroll.Section)).ToList(); if (collection.Count > 0 && student != null) { foreach (AcademicYear academicYear in collection) { var myEnroll = new Enroll { AcademicYear = academicYear, Student = student }; _enrollRepository.Create(myEnroll); } const string title = "Estudiante Agregado"; const string content = "El estudiante ha sido matriculado exitosamente."; _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage); } else { const string title = "Estudiante No Agregado"; const string content = "El estudiante no se logro matricular."; _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.ErrorMessage); } return RedirectToAction("Index"); }
public Enroll Create(Enroll itemToCreate) { var enroll = _context.Enrolls.Add(itemToCreate); _context.Entry(enroll.AcademicYear).State = EntityState.Modified; _context.Entry(enroll.Student).State = EntityState.Modified; _context.SaveChanges(); return enroll; }
public Enroll Update(Enroll itemToUpdate, bool academicYear, bool student) { if (academicYear) { _context.Entry(itemToUpdate.AcademicYear).State = EntityState.Modified; } if (student) { _context.Entry(itemToUpdate.Student).State = EntityState.Modified; } _context.SaveChanges(); return itemToUpdate; }
public Enroll Update(Enroll itemToUpdate) { var enroll = GetById(itemToUpdate.Id); bool academicYear = false; bool student = false; if (enroll.AcademicYear != itemToUpdate.AcademicYear) { enroll.AcademicYear = itemToUpdate.AcademicYear; academicYear = true; } if (enroll.Student != itemToUpdate.Student) { enroll.Student = itemToUpdate.Student; student = true; } return Update(enroll, academicYear, student); }
public void Detach(Enroll enroll) { _context.Entry(enroll).State = EntityState.Detached; }