public async Task Change(Major major) { if (major == null) { throw new Exception("Must enter a Major ID"); } if (major.Id < 0) { throw new Exception("Major Id must be greater than ZERO"); } _context.Entry(major).State = Microsoft.EntityFrameworkCore.EntityState.Modified; var rowsAffected = await _context.SaveChangesAsync(); if (rowsAffected != 1) { throw new Exception("Change Failed"); } return; }
//// we are doing a create method here to use in programs //public Student Create(Student student) { // if(student == null) { // throw new Exception("Student cannot be null!"); // } // if(student.Id != 0) { // throw new Exception("student.Id must be zero!"); // } // _context.Students.Add(student); // var rowsAffect = _context.SaveChanges();// it's important to remember to do SaveChanges // if(rowsAffect != 1) { // throw new Exception("Create failed!"); // } // return student; //} // change does not need a return // we also took out void where task used to be becasue it needs to be async public async Task Change(Student student) { if (student == null) { throw new Exception("Student cannot be null!"); } if (student.Id <= 0) { throw new Exception("student.Id must be greater than zero!"); } _context.Entry(student).State = Microsoft.EntityFrameworkCore.EntityState.Modified; // we are telling entity to change the data here and to map it. var rowsAffect = await _context.SaveChangesAsync(); // it's important to remember to do SaveChanges if (rowsAffect != 1) { throw new Exception("Change failed!"); } return; }
public void change(Student student) { if (student == null) { throw new Exception("Student cannot be NULL"); } if (student.Id <= 0) { throw new Exception("Student.Id must be greater than zero!"); } _context.Entry(student).State = Microsoft.EntityFrameworkCore.EntityState.Modified; var rowsAffected = _context.SaveChanges(); if (rowsAffected != 1) { throw new Exception("Change failed!"); } return; }
public void change(Major major) { if (major == null) { throw new Exception("Major cannot be NULL"); } if (major.Id <= 0) { throw new Exception("Major.Id has to be greater than zero"); } _context.Entry(major).State = Microsoft.EntityFrameworkCore.EntityState.Modified; var rowsAffected = _context.SaveChanges(); if (rowsAffected != 1) { throw new Exception("Change Failed"); } return; }
public async Task Change(Student student) { if (student == null) { throw new Exception("Student cannot be null"); } if (student.Id < 0) { throw new Exception("Student.Id must be greater than zero!"); } _context.Entry(student).State = Microsoft.EntityFrameworkCore.EntityState.Modified; // this is the cache holder for the data from the database var rowsAffected = await _context.SaveChangesAsync(); if (rowsAffected != 1) { throw new Exception("Change failed!"); } return; }