public Enrollment Promote(int idStudy, int semester) { var getEnrollment = GetEnrollment(idStudy, semester); if (getEnrollment == null) { return(null); } var setEnrollment = GetEnrollment(idStudy, semester + 1); if (setEnrollment == null) { setEnrollment = new Enrollment { IdEnrollment = _dbcont.Enrollments.Max(e => e.IdEnrollment) + 1, IdStudy = getEnrollment.IdStudy, Semester = getEnrollment.Semester + 1 }; _dbcont.Attach(setEnrollment); _dbcont.Add(setEnrollment); } _dbcont.Students .Where(s => s.IdEnrollment == getEnrollment.IdEnrollment) .ToList() .ForEach(s => { s.IdEnrollment = setEnrollment.IdEnrollment; _dbcont.Attach(s); _dbcont.Entry(s).State = EntityState.Modified; }); _dbcont.SaveChanges(); return(setEnrollment); }
public ActionResult UpdateStudentEF(UpdateStudentRequest request) { var db = new s16061Context(); var res = new Students { IndexNumber = request.IndexNumber, FirstName = request.FirstName, LastName = request.LastName, Birthdate = request.Birthdate, IdEnrollment = request.IdEnrollment }; db.Entry(res).State = EntityState.Modified; db.SaveChanges(); return(Ok("Zaktualizowano")); }