Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Pondar/Pondar.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StudentWebApi", "StudentWebApi\StudentWebApi.csproj", "{A8C92177-1350-965C-6BE8-531807497CF0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A8C92177-1350-965C-6BE8-531807497CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A8C92177-1350-965C-6BE8-531807497CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A8C92177-1350-965C-6BE8-531807497CF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A8C92177-1350-965C-6BE8-531807497CF0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {192F50C0-330E-48CF-ACE9-98131970497B}
EndGlobalSection
EndGlobal
68 changes: 68 additions & 0 deletions Pondar/StudentWebApi/Controllers/StudentController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Microsoft.AspNetCore.Mvc;
using StudentWebApi.Models;
using StudentWebApi.Services;

[ApiController]
[Route("api/[controller]")]
public class StudentController : ControllerBase
{
private IStudentService _studentService;

public StudentController(IStudentService studentService)
{
_studentService = studentService;
}

[HttpPost]
public IActionResult AddStudent([FromBody] Student student)
{
try
{
Student studentToAdd = _studentService.addStudent(student);
return Ok(studentToAdd);
}
catch (ArgumentException)
{
return BadRequest("ID is already taken!");
}
}

[HttpGet]
public ActionResult<List<Student>> GetAllStudent()
{
return Ok(_studentService.getAllStudents());
}

[HttpGet("{id}")]
public ActionResult<Student> GetStudentById(long id)
{

var student = _studentService.getStudentById(id);

if (student == null)
{
return NotFound($"Student with ID {id} not found.");
}
return Ok(student);
}

[HttpPut("{id}")]
public IActionResult UpdateStudent(long id, [FromBody] Student student)
{
student.PkStudentID = id;
var updatedStudent = _studentService.updateStudent(id, student);

if (updatedStudent == null)
{
return NotFound($"Student {id} not found");
}

return Ok(updatedStudent);
}
[HttpDelete("{id}")]
public ActionResult<bool> DeleteStudent(long id)
{
return _studentService.deleteStudent(id) ? Ok($"Student is removed successfully") : NotFound($"Student ID not found");
}

}
18 changes: 18 additions & 0 deletions Pondar/StudentWebApi/Models/Student.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace StudentWebApi.Models
{
public class Student
{
public long PkStudentID { get; set; }
public string Name { get; set; } = string.Empty;
public string Course { get; set; } = string.Empty;

public Student() { }

public Student(long pkStudentID, string name, string course)
{
PkStudentID = pkStudentID;
Name = name;
Course = course;
}
}
}
28 changes: 28 additions & 0 deletions Pondar/StudentWebApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using StudentWebApi.Models;
using StudentWebApi.Services;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();

// For Dependency Injection (Uses a single instance of dictionary; which is the in-memory studentDb)
builder.Services.AddSingleton<IStudentService, StudentService>();

// For Controller
builder.Services.AddControllers();

var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())

{
app.MapOpenApi();

}

app.UseHttpsRedirection();
app.MapControllers();

app.Run();
23 changes: 23 additions & 0 deletions Pondar/StudentWebApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:9090",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7053;http://localhost:9090",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
13 changes: 13 additions & 0 deletions Pondar/StudentWebApi/Services/Implementations/IStudentService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using StudentWebApi.Models;

namespace StudentWebApi.Services
{
public interface IStudentService
{
Student addStudent(Student student);
List<Student> getAllStudents();
Student? getStudentById(long id);
Student? updateStudent(long id, Student student);
bool deleteStudent(long id);
}
}
66 changes: 66 additions & 0 deletions Pondar/StudentWebApi/Services/Interface/StudentService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using StudentWebApi.Models;
using StudentWebApi.Services;

public class StudentService : IStudentService
{
private Dictionary<long, Student> studentDB = new Dictionary<long, Student>();
private long studentCount = 1;

public Student addStudent(Student student)
{
if (student.PkStudentID == 0)
{
student.PkStudentID = studentCount++;
}

if (studentDB.ContainsKey(student.PkStudentID))
{
throw new ArgumentException("Student ID already exists");
}

studentDB.Add(student.PkStudentID, student);
return student;
}
public List<Student> getAllStudents()
{
return studentDB.Values.ToList();
}

public bool deleteStudent(long id)
{
return studentDB.Remove(id);
}

public Student? getStudentById(long id)
{
return studentDB.TryGetValue(id, out Student? student) ? student : null;

// Student? foundStudentID;
// if (studentDB.TryGetValue(id, out Student? student))
// {
// foundStudentID = student;
// }
// else
// {
// foundStudentID = null;
// }
}

public Student? updateStudent(long id, Student student)
{
long studentID = student.PkStudentID;

if (studentDB.ContainsKey(studentID))
{
studentDB[studentID].Name = student.Name;
studentDB[studentID].Course = student.Course;

return studentDB[id];

}
else
{
return null;
}
}
}
13 changes: 13 additions & 0 deletions Pondar/StudentWebApi/StudentWebApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.3" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions Pondar/StudentWebApi/StudentWebApi.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@StudentWebApi_HostAddress = http://localhost:5052

GET {{StudentWebApi_HostAddress}}/weatherforecast/
Accept: application/json

###
8 changes: 8 additions & 0 deletions Pondar/StudentWebApi/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions Pondar/StudentWebApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Binary file not shown.
Binary file not shown.
59 changes: 59 additions & 0 deletions Pondar/StudentWebApi/bin/Debug/net9.0/StudentWebApi.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {
"StudentWebApi/1.0.0": {
"dependencies": {
"Microsoft.AspNetCore.OpenApi": "9.0.3"
},
"runtime": {
"StudentWebApi.dll": {}
}
},
"Microsoft.AspNetCore.OpenApi/9.0.3": {
"dependencies": {
"Microsoft.OpenApi": "1.6.17"
},
"runtime": {
"lib/net9.0/Microsoft.AspNetCore.OpenApi.dll": {
"assemblyVersion": "9.0.3.0",
"fileVersion": "9.0.325.11220"
}
}
},
"Microsoft.OpenApi/1.6.17": {
"runtime": {
"lib/netstandard2.0/Microsoft.OpenApi.dll": {
"assemblyVersion": "1.6.17.0",
"fileVersion": "1.6.17.0"
}
}
}
}
},
"libraries": {
"StudentWebApi/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Microsoft.AspNetCore.OpenApi/9.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-fKh0UyGMUE+lhbovMhh3g88b9bT+y2jfZIuJ8ljY7rcCaSJ9m2Qqqbh66oULFfzWE2BUAmimzTGcPcq3jXi/Ew==",
"path": "microsoft.aspnetcore.openapi/9.0.3",
"hashPath": "microsoft.aspnetcore.openapi.9.0.3.nupkg.sha512"
},
"Microsoft.OpenApi/1.6.17": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Le+kehlmrlQfuDFUt1zZ2dVwrhFQtKREdKBo+rexOwaCoYP0/qpgT9tLxCsZjsgR5Itk1UKPcbgO+FyaNid/bA==",
"path": "microsoft.openapi/1.6.17",
"hashPath": "microsoft.openapi.1.6.17.nupkg.sha512"
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "9.0.0"
}
],
"configProperties": {
"System.GC.Server": true,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Version": 1,
"ManifestType": "Build",
"Endpoints": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions Pondar/StudentWebApi/bin/Debug/net9.0/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Loading