Skip to content

Commit

Permalink
Add new ASP.NET Core project for student management
Browse files Browse the repository at this point in the history
Introduce a new ASP.NET Core project focused on managing student-related operations and handling global exceptions. Key components include:

- Database context and initial migration for `Student` entity.
- Configuration for services, OpenAPI/Swagger, and exception handling.
- Models and DTOs for `Student` entity.
- Service layer with `IStudentService` and `StudentService`.
- `StudentController` for CRUD operations.
- Global exception handling with `GlobalExceptionHandler`.
- Added new solution and project files, including `GlobalExceptions.sln` and `GlobalExceptions.csproj`.
- Updated various metadata and configuration files.
  • Loading branch information
Clifftech123 committed Dec 5, 2024
1 parent 1c6fb48 commit 22744ce
Show file tree
Hide file tree
Showing 35 changed files with 710 additions and 46 deletions.
22 changes: 22 additions & 0 deletions GlobalExceptions/GlobalExceptions.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35506.116 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GlobalExceptions", "GlobalExceptions\GlobalExceptions.csproj", "{DACC5DD3-A363-4A33-B169-DAF873F7ADC4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DACC5DD3-A363-4A33-B169-DAF873F7ADC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DACC5DD3-A363-4A33-B169-DAF873F7ADC4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DACC5DD3-A363-4A33-B169-DAF873F7ADC4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DACC5DD3-A363-4A33-B169-DAF873F7ADC4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
21 changes: 21 additions & 0 deletions GlobalExceptions/GlobalExceptions/GlobalExceptions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

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

<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace GlobalExceptions.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Biography = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Students", x => x.Id);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Students");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace GlobalExceptions.Migrations
{
/// <inheritdoc />
public partial class Update : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{

}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// <auto-generated />
using GlobalExceptions.src.Context;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

#nullable disable

namespace GlobalExceptions.Migrations
{
[DbContext(typeof(StudentDbContext))]
partial class StudentDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

modelBuilder.Entity("GlobalExceptions.src.Modles.Student", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");

SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));

b.Property<string>("Biography")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.HasKey("Id");

b.ToTable("Students");
});
#pragma warning restore 612, 618
}
}
}
23 changes: 23 additions & 0 deletions GlobalExceptions/GlobalExceptions/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:5083",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7236;http://localhost:5083",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
14 changes: 14 additions & 0 deletions GlobalExceptions/GlobalExceptions/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},

"ConnectionStrings": {
"sqlConnection": "Server=localhost;Database=studentDb;Integrated Security=true;TrustServerCertificate=true;"
},

"AllowedHosts": "*"
}
9 changes: 9 additions & 0 deletions GlobalExceptions/GlobalExceptions/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
13 changes: 13 additions & 0 deletions GlobalExceptions/GlobalExceptions/src/Context/StudentDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using GlobalExceptions.src.Modles;
using Microsoft.EntityFrameworkCore;

namespace GlobalExceptions.src.Context
{
public class StudentDbContext : DbContext
{
public StudentDbContext(DbContextOptions<StudentDbContext> options) : base(options)
{
}
public DbSet<Student> Students { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GlobalExceptions.src.Contracts
{
public class ErrorResponse
{
public string Title { get; set; }
public int StatusCode { get; set; }
public string Message { get; set; }
}
}
6 changes: 6 additions & 0 deletions GlobalExceptions/GlobalExceptions/src/Contracts/StudentDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace GlobalExceptions.src.Contracts
{
public record CreateStudent(string Name, string Biography);
public record UpdateStudent(int Id, string Name, string Biography);
public record StudentDto(int Id, string Name, string Biography);
}
Loading

0 comments on commit 22744ce

Please sign in to comment.