public API_ErrorModel AddStudent(Students students) { try { _context.Students.Add(students); _context.SaveChanges(); var model = new API_ErrorModel("Thành Công", "Thêm thành công"); return(model); } catch { var model = new API_ErrorModel("Thất Bại", "Thêm thất bại"); return(model); } }
public API_ErrorModel UpdateStudent(int id, Students students) { var student = _context.Students.SingleOrDefault(p => p.StudentId == id); if (student == null) { var model = new API_ErrorModel("Thất bại", "Không tìm thấy Student"); return(model); } _context.Students.Update(student); try { _context.SaveChanges(); var model = new API_ErrorModel("Thành công", "Cập nhật thành công"); return(model); } catch { var model = new API_ErrorModel("Thất bại", "Cập nhật thất bại"); return(model); } }
public API_ErrorModel DeleteStudent(int id) { var student = _context.Students.SingleOrDefault(p => p.StudentId == id); if (student == null) { var model = new API_ErrorModel("Thất bại", "Không tìm thấy Student"); return(model); } _context.Students.Attach(student); _context.Students.Remove(student); try { _context.SaveChanges(); var model = new API_ErrorModel("Thành công", "Xóa thành công"); return(model); } catch { var model = new API_ErrorModel("Thất bại", "Xóa thất bại"); return(model); } }