NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;

[ApiController]
[Route("[controller]")]
public class StudentController : ControllerBase
{
private static List<Student> students10 = new List<Student>
{
new Student { Id = 1, Name = "Student1", Assignment = "Math", Attendance = "90%", Contact = "1234567890", Class = 10 },
// Add more students as needed
};

private static List<Student> students11 = new List<Student>
{
new Student { Id = 1, Name = "Student11", Assignment = "Physics", Attendance = "85%", Contact = "9876543210", Class = 11 },
// Add more students as needed
};

private static List<Student> students12 = new List<Student>
{
new Student { Id = 1, Name = "Student21", Assignment = "Chemistry", Attendance = "92%", Contact = "5555555555", Class = 12 },
// Add more students as needed
};

[HttpGet("10")]
public ActionResult<IEnumerable<Student>> GetStudents10()
{
return Ok(students10);
}

[HttpGet("11")]
public ActionResult<IEnumerable<Student>> GetStudents11()
{
return Ok(students11);
}

[HttpGet("12")]
public ActionResult<IEnumerable<Student>> GetStudents12()
{
return Ok(students12);
}

[HttpPost("10/add")]
public ActionResult<Student> AddStudent10([FromBody] Student student)
{
student.Id = GenerateStudentId(students10);
students10.Add(student);
return CreatedAtAction(nameof(GetStudents10), students10);
}

[HttpPost("11/add")]
public ActionResult<Student> AddStudent11([FromBody] Student student)
{
student.Id = GenerateStudentId(students11);
students11.Add(student);
return CreatedAtAction(nameof(GetStudents11), students11);
}

[HttpPost("12/add")]
public ActionResult<Student> AddStudent12([FromBody] Student student)
{
student.Id = GenerateStudentId(students12);
students12.Add(student);
return CreatedAtAction(nameof(GetStudents12), students12);
}

[HttpPut("{classNumber}/update/{id}")]
public IActionResult UpdateStudent(int classNumber, int id, [FromBody] Student updatedStudent)
{
List<Student> students = GetStudentsByClass(classNumber);

Student existingStudent = students.FirstOrDefault(s => s.Id == id);

if (existingStudent == null)
return NotFound("Student not found");

existingStudent.Name = updatedStudent.Name;
existingStudent.Assignment = updatedStudent.Assignment;
existingStudent.Attendance = updatedStudent.Attendance;
existingStudent.Contact = updatedStudent.Contact;

return NoContent();
}

[HttpDelete("{classNumber}/delete/{id}")]
public IActionResult DeleteStudent(int classNumber, int id)
{
List<Student> students = GetStudentsByClass(classNumber);

Student existingStudent = students.FirstOrDefault(s => s.Id == id);

if (existingStudent == null)
return NotFound("Student not found");

students.Remove(existingStudent);
return NoContent();
}

private int GenerateStudentId(List<Student> students)
{
// Generate a unique student ID (example: increment the last student ID)
return students.Count + 1;
}

private List<Student> GetStudentsByClass(int classNumber)
{
switch (classNumber)
{
case 10:
return students10;
case 11:
return students11;
case 12:
return students12;
default:
return new List<Student>();
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.