Skip to content

Repository files navigation

WEB API for schoolAdministration

This API, written in C#, is intended as a backend for an Angular website for school administration.

  • A student can take courses, have diplomas and certificates, create studyplans, take an exam and view his(her) results.

  • A person (student, teacher, ...) can have more than one address.

  • With the help of a studyplan, the student can plan a learning period, for example for a specific exam.

  • A teacher can create courses,exams and homework.

  • A teacher can give exam grades for a specific student

  • Schoolmanagement can make invoices.

  • ... and more

image

How to get the application :

  • Click button Code
  • Choose open with Visual Studio
  • Click Clone

How to start the application :

  • Setup the database in SQL-Server

file appsettings.json :

Replace the Connectionstring, AppiSettings-SecretKey , Cors-AllowedOrigins and the AutoMapper-LicenseKey with your settings

Visual studio:

  • Start the application in Visual Studio by clicking the Startbutton (choose https) image

  • The application start now the Swagger-screen where you can explore the available endpoints.

Development:

  • Visual studio 2026 Community Edition

  • Target framework : .NET9.0

  • SQL-Server 2022

  • Database diagram :

schoolApiDatabaseSchema

Swagger :

Exploring Endpoints.

localhost_7213_index html (4)

Execute Get-method /api/Course:

image

UnitTests :

image

add new project to solution : xUnit test Project

Installed Packages:

  • xunit
  • xunit.runner.visualstudio

Right click project SchoolAdministration

Choose Manage Nuget Packages

Search and install Nuget-Packages:

  • FluentAssertions
  • Moq

Make a reference to SchoolAdministration project:

Right click project SchoolAdministrationTests

choose Project Reference

Cross-origin-requests :

Cors

Program.cs:

image

Warning :

  • This are my settings for now.
  • Will be reviewed later.
  • Be carefully with security settings, especially in production environment.

Logging :

Installed NuGet-packages :

  • Serilog.AspNetCore
  • Serilog.Sinks.file

Program.cs:

image

If you choose RollingInterval.Day : You get EVERYDAY DAY a separete log file : Filename = SchoolManagement + date(yyyyMMdd) .log :

image

StudentController: _logger.LogInformation("Getting all the students.")

EntityFrameworkCore:

Installed NuGet-packages :

  • microsoft.entityframeworkcore.sqlserver\9.0.0
  • entityframeworkcore.tools\9.0.0

We use code first.

By Migrations we keep our database in SQL-Server in Sync.

image

example:

Type in Package Manager Console:

Add-Migration InitialMigration

update-Database

Authentication:

Installed Nuget-packages :

  • microsoft.aspnetcore.identity.entityframeworkcore\9.0.0\
  • microsoft.aspnetcore.authentication.jwtbearer\9.0.3\

extra tables in SQL-Server:

image

Dependecy Injection :

Why we use Dependecy Injection?

Dependency injection aims to separate the concerns of constructing objects and using them, leading to loosely coupled programs.

We use DI for injection from : studentRepository,logger and mapper

public StudentController( IStudentRepository studentRepository, ILogger logger, IMapper mapper)

In program.cs we must configure:

builder.Services.AddScoped<IStudentRepository, StudentRepository>();

AutoMapper :

Installed NuGet-package :

  • automapper

To map entities to DTO's and vice versa.

DTO stands for Data Transfer Objects

Why we need DTO's to communicate with the outside world?

Example : in our database we have fields to store 'insertDate' or 'insertedBy'

If we don't won't to share this fields with the outside world : we make a DTO without these fields.

We use par Controller 3 DTO's : one for update, one for insert, one for read

Why?

Because we do not need always the same data.

Example : for insert we do not need a ID, for a update is ID necessary.

MappingConfig:

CreateMap<Student, StudentDTO>().ReverseMap();

In the Controller we can write some like this to map student to StudentDTO :

_mapper.Map < StudentDTO > (student)

Note : In the latest version of Automapper, you need a license key. Check te website: https://AutoMapper.io

Manual Mapping :

I am considering to switch from automapper to manual mapping. Both have its pros and contras. I Started with the conversion of the CourseController from automapper to manual mapping.

Manual mapping with EXTENSION METHODS :

CourseController.cs:

Schermafbeelding 2026-07-23 180341

CourseMappingExtensions.cs :

image

Versioning :

image

Installed NuGet-packages :

  • Microsoft.AspNetCore.Mvc.Versioning

  • Microsoft.AspNetCore.Mvc.Versioning.ApiExlorer

    Program.cs :

builder.Services.AddApiVersioning(options => { options.AssumeDefaultVersionWhenUnspecified = true; options.DefaultApiVersion = new Microsoft.AspNetCore.Mvc.ApiVersion(1, 0); });

More Info / Documentation :

If you want to read more info about this API or the used technology :

More Info / Documentation

Analyse:

Analyse