//PUT Methods public string UpdateBook(Students student, string NIM) { bool updated = repository.UpdateAStudents(student); if (updated) return "Student with id = " + NIM + " updated successfully"; else return "Unable to update student with NIM = " + NIM; }
//1. Create Students public Students AddNewStudents(Students newStudent) { if (newStudent == null) throw new ArgumentNullException("newStudent"); newStudent.NIM = counter++; students.Add(newStudent); return newStudent; }
//3. Update Students public bool UpdateAStudents(Students updatedStudents) { if (updatedStudents == null) throw new ArgumentNullException("updatedStudent"); int idx = students.FindIndex(b => b.NIM == updatedStudents.NIM); if (idx == -1) return false; students.RemoveAt(idx); students.Add(updatedStudents); return true; }
//POST Methods public string AddBook(Students student, string NIM) { Students newStudent = repository.AddNewStudents(student); return "NIM =" + newStudent.NIM; }