-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDAW_Tema2.cs
More file actions
56 lines (47 loc) · 1.43 KB
/
DAW_Tema2.cs
File metadata and controls
56 lines (47 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Lab2_24.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
namespace Lab2_24.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class StudentsController : ControllerBase
{
public static List<Student> students = new List<Student>
{
new Student { Id = 1, Name = "Ana", Age = 21 },
new Student { Id = 2, Name = "Maria", Age = 19 },
new Student { Id = 3, Name = "Vlad", Age = 22 },
new Student { Id = 4, Name = "Florin", Age = 25 },
new Student { Id = 5, Name = "Marian", Age = 20 },
};
[HttpGet("getAllOrdered")]
public List<Student> GetAllOrdered()
{
return students.OrderByDescending(s => s.Name).ToList();
}
[HttpGet]
public List<Student> Get()
{
return students;
}
[HttpPost]
public List<Student> Add(Student student)
{
students.Add(student);
return students;
}
[HttpDelete("id")]
public List<Student> Delete(int id)
{
var student = students.FirstOrDefault(s => s.Id == id);
if (student != null)
{
students.Remove(student);
}
return students;
}
}
}