public async Task <int> UpdateAsync(Student student) { _context.Attach(student).State = EntityState.Modified; int changes = await _context.SaveChangesAsync(); return(await Task.FromResult(changes)); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Course).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseExists(Course.CourseID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public IActionResult OnPostEdit() { if (!ModelState.IsValid) { return(View()); } _context.Attach(Student).State = EntityState.Modified; try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(Student.ID)) { return(NotFound()); } else { throw; } } return(View("List", _context.Student.ToList())); }
public ActionResult DeleteStudent(long studentId) { var student = new Student { StudentId = studentId }; _dbContext.Attach(student); _dbContext.Remove(student); _dbContext.SaveChanges(); return(Ok()); }
public ActionResult DeleteInstructor(long instructorId) { var instructor = new Instructor { InstructorId = instructorId }; _dbContext.Attach(instructor); _dbContext.Remove(instructor); _dbContext.SaveChanges(); return(Ok()); }
public void UpdateKabinets(SchoolContext context, int selectedKabinet, SchoolClass schoolClass) { var schoolClassKabinet = schoolClass.SchoolClassKabinetAssignment.KabinetId; context.Attach(schoolClass).State = EntityState.Modified; context.Remove(schoolClass.SchoolClassKabinetAssignment); schoolClass.SchoolClassKabinetAssignment = new SchoolClassKabinetAssignment() { KabinetId = schoolClass.Id, SchoolClassId = selectedKabinet }; }
public void Update(T entity) { var avoidingAttachedEntity = GetById(entity.Id); _context.Entry(avoidingAttachedEntity).State = EntityState.Detached; var entry = _context.Entry(entity); if (entry.State == EntityState.Detached) { _context.Attach(entity); } _context.Entry(entity).State = EntityState.Modified; _context.SaveChanges(); }