Создана БД + круд студентов

This commit is contained in:
2025-05-25 20:59:57 +04:00
parent 26f5166610
commit 9dbb2abf90
34 changed files with 1855 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
using GradeBookServer.Domain.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Application.DTOs.Student
{
public class GradeInStudentDto
{
public int ID { get; set; }
public GradeValue GradeValue { get; set; }
public int VedomostID { get; set; }
public string DisciplineName { get; set; } = string.Empty;
public int Semester { get; set; }
public DateOnly AcademicYear { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Application.DTOs.Student
{
public class StudentCreateDto
{
public string FullName { get; set; } = string.Empty;
public int Age { get; set; }
public int GroupID { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Application.DTOs.Student
{
public class StudentReadDto
{
public int ID { get; set; }
public required string FullName { get; set; }
public int Age { get; set; }
public int GroupID { get; set; }
public string? GroupName { get; set; }
public List<GradeInStudentDto> Grades { get; set; } = new();
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Application.DTOs.Student
{
public class StudentTableDto
{
public int ID { get; set; }
public required string FullName { get; set; }
public int Age { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\GradeBookServer.Domain\GradeBookServer.Domain.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,21 @@
using GradeBookServer.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Application.Interfaces
{
public interface IBaseRepository<TEntity> where TEntity : class
{
Task<TEntity?> GetByIdAsync(int id);
Task<IEnumerable<TEntity>?> GetAllAsync();
Task AddAsync(TEntity entity);
Task UpdateAsync(TEntity entity);
Task DeleteAsync(int id);
Task<TEntity?> GetByIdWithIncludeAsync(
int id, Expression<Func<TEntity, bool>> idSelector, params Expression<Func<TEntity, object>>[] includes);
}
}

View File

@@ -0,0 +1,96 @@
using GradeBookServer.Application.DTOs.Student;
using GradeBookServer.Application.Interfaces;
using GradeBookServer.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Application.Services
{
public class StudentService
{
private readonly IBaseRepository<Student> _baseRepository;
public StudentService(IBaseRepository<Student> baseRepository)
{
_baseRepository = baseRepository;
}
public async Task<StudentReadDto?> GetStudentByIdAsync(int id)
{
var student = await _baseRepository.GetByIdWithIncludeAsync(
id,
s => s.ID == id,
s => s.Group!,
s => s.Grades,
s => s.Grades.Select(g => g.Vedomost),
s => s.Grades.Select(g => g.Vedomost!.Discipline)
);
if (student == null)
return null;
return new StudentReadDto
{
ID = student.ID,
FullName = student.FullName,
Age = student.Age,
GroupName = student.Group?.Name ?? "—",
Grades = student.Grades.Select(g => new GradeInStudentDto
{
ID = g.ID,
GradeValue = g.GradeValue,
DisciplineName = g.Vedomost?.Discipline?.Name ?? "Не указано",
Semester = g.Vedomost?.Semester ?? 0,
AcademicYear = g.Vedomost?.AcademicYear ?? default
}).ToList()
};
}
public async Task<IEnumerable<StudentTableDto>?> GetAllStudentsAsync()
{
var students = await _baseRepository.GetAllAsync();
if (students == null)
return null;
return students.Select(s => new StudentTableDto
{
ID = s.ID,
FullName = s.FullName,
Age = s.Age
});
}
public async Task AddStudentAsync(StudentCreateDto studentDto)
{
var student = new Student
{
FullName = studentDto.FullName,
Age = studentDto.Age,
GroupID = studentDto.GroupID
};
await _baseRepository.AddAsync(student);
}
public async Task UpdateStudentAsync(int id, StudentCreateDto dto)
{
var student = await _baseRepository.GetByIdAsync(id);
if (student == null) return;
student.FullName = dto.FullName;
student.Age = dto.Age;
student.GroupID = dto.GroupID;
await _baseRepository.UpdateAsync(student);
}
public async Task DeleteStudentAsync(int id)
{
await _baseRepository.DeleteAsync(id);
}
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace GradeBookServer.Domain.Entities
{
public class Direction
{
public int ID { get; set; }
public required string Name { get; set; }
public int FacultyID { get; set; }
public Faculty? Faculty { get; set; }
public ICollection<Discipline> Disciplines { get; set; } = new List<Discipline>();
public ICollection<Group> Groups { get; set; } = new List<Group>();
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Domain.Entities
{
public class Discipline
{
public int ID { get; set; }
public required string Name { get; set; }
public int TotalHours { get; set; }
public ICollection<Direction> Directions { get; set; } = new List<Direction>();
public ICollection<Vedomost> Vedomosti { get; set; } = new List<Vedomost>();
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Domain.Entities
{
public class Faculty
{
public int ID { get; set; }
public required string Name { get; set; }
public ICollection<Direction> Directions { get; set; } = new List<Direction>();
}
}

View File

@@ -0,0 +1,22 @@
using GradeBookServer.Domain.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Domain.Entities
{
public class Grade
{
public int ID { get; set; }
public int StudentID { get; set; }
public Student? Student { get; set; }
public int VedomostID { get; set; }
public Vedomost? Vedomost { get; set; }
public GradeValue GradeValue { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Domain.Entities
{
public class Group
{
public int ID { get; set; }
public required string Name { get; set; }
public int DirectionID { get; set; }
public Direction? Direction { get; set; }
public ICollection<Student> Students { get; set; } = new List<Student>();
public ICollection<Vedomost> Vedomosti { get; set; } = new List<Vedomost>();
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Domain.Entities
{
public class Student
{
public int ID { get; set; }
public required string FullName { get; set; }
public int Age { get; set; }
public int GroupID { get; set; }
public Group? Group { get; set; }
public ICollection<Grade> Grades { get; set; } = new List<Grade>();
}
}

View File

@@ -0,0 +1,22 @@
using GradeBookServer.Domain.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Domain.Entities
{
public class User
{
public int Id { get; set; }
public required string Name { get; set; }
public required string Email { get; set; }
public string? PhoneNumber { get; set; }
public required string Password { get; set; }
public UserRole Role { get; set; }
public ICollection<Vedomost> Vedomosti { get; set; } = new List<Vedomost>();
}
}

View File

@@ -0,0 +1,30 @@
using GradeBookServer.Domain.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Domain.Entities
{
public class Vedomost
{
public int ID { get; set; }
public ExamType ExamType { get; set; }
public StatusVedomost Status { get; set; }
public DateOnly AcademicYear { get; set; }
public int Semester { get; set; }
public int Hours { get; set; }
public int GroupID { get; set; }
public Group? Group { get; set; }
public int DisciplineID { get; set; }
public Discipline? Discipline { get; set; }
public int? ProfessorID { get; set; }
public User? Professor { get; set; }
public ICollection<Grade> Grades { get; set; } = new List<Grade>();
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Domain.Enums
{
public enum ExamType
{
Pass,
Exam,
GradedPass,
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Domain.Enums
{
public enum GradeValue
{
Excellent,
Good,
Satisfactory,
Fail,
Absence,
Pass,
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Domain.Enums
{
public enum StatusVedomost
{
Draft,
Completed,
Approved,
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Domain.Enums
{
public enum UserRole
{
Employee,
Professor,
}
}

View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,27 @@
using GradeBookServer.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Infrastructure.Data
{
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<Group> Groups { get; set; }
public DbSet<Student> Students { get; set; }
public DbSet<Direction> Directions { get; set; }
public DbSet<Discipline> Disciplines { get; set; }
public DbSet<Faculty> Faculties { get; set; }
public DbSet<Vedomost> Vedomosti { get; set; }
public DbSet<Grade> Grades { get; set; }
public DbSet<User> Users { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GradeBookServer.Application\GradeBookServer.Application.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,380 @@
// <auto-generated />
using System;
using GradeBookServer.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace GradeBookServer.Infrastructure.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20250525163835_AllBD")]
partial class AllBD
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.5")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DirectionDiscipline", b =>
{
b.Property<int>("DirectionsID")
.HasColumnType("integer");
b.Property<int>("DisciplinesID")
.HasColumnType("integer");
b.HasKey("DirectionsID", "DisciplinesID");
b.HasIndex("DisciplinesID");
b.ToTable("DirectionDiscipline");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Direction", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<int>("FacultyID")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("FacultyID");
b.ToTable("Directions");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Discipline", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("TotalHours")
.HasColumnType("integer");
b.HasKey("ID");
b.ToTable("Disciplines");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Faculty", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.ToTable("Faculties");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Grade", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<int>("GradeValue")
.HasColumnType("integer");
b.Property<int>("StudentID")
.HasColumnType("integer");
b.Property<int>("VedomostID")
.HasColumnType("integer");
b.HasKey("ID");
b.HasIndex("StudentID");
b.HasIndex("VedomostID");
b.ToTable("Grades");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Group", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<int>("DirectionID")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("DirectionID");
b.ToTable("Groups");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Student", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<int>("Age")
.HasColumnType("integer");
b.Property<string>("FullName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("GroupID")
.HasColumnType("integer");
b.HasKey("ID");
b.HasIndex("GroupID");
b.ToTable("Students");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<int>("Role")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Vedomost", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<DateOnly>("AcademicYear")
.HasColumnType("date");
b.Property<int>("DisciplineID")
.HasColumnType("integer");
b.Property<int>("ExamType")
.HasColumnType("integer");
b.Property<int>("GroupID")
.HasColumnType("integer");
b.Property<int>("Hours")
.HasColumnType("integer");
b.Property<int?>("ProfessorID")
.HasColumnType("integer");
b.Property<int>("Semester")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.HasKey("ID");
b.HasIndex("DisciplineID");
b.HasIndex("GroupID");
b.HasIndex("ProfessorID");
b.ToTable("Vedomosti");
});
modelBuilder.Entity("DirectionDiscipline", b =>
{
b.HasOne("GradeBookServer.Domain.Entities.Direction", null)
.WithMany()
.HasForeignKey("DirectionsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GradeBookServer.Domain.Entities.Discipline", null)
.WithMany()
.HasForeignKey("DisciplinesID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Direction", b =>
{
b.HasOne("GradeBookServer.Domain.Entities.Faculty", "Faculty")
.WithMany("Directions")
.HasForeignKey("FacultyID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Faculty");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Grade", b =>
{
b.HasOne("GradeBookServer.Domain.Entities.Student", "Student")
.WithMany("Grades")
.HasForeignKey("StudentID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GradeBookServer.Domain.Entities.Vedomost", "Vedomost")
.WithMany("Grades")
.HasForeignKey("VedomostID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Student");
b.Navigation("Vedomost");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Group", b =>
{
b.HasOne("GradeBookServer.Domain.Entities.Direction", "Direction")
.WithMany("Groups")
.HasForeignKey("DirectionID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Direction");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Student", b =>
{
b.HasOne("GradeBookServer.Domain.Entities.Group", "Group")
.WithMany("Students")
.HasForeignKey("GroupID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Group");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Vedomost", b =>
{
b.HasOne("GradeBookServer.Domain.Entities.Discipline", "Discipline")
.WithMany("Vedomosti")
.HasForeignKey("DisciplineID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GradeBookServer.Domain.Entities.Group", "Group")
.WithMany("Vedomosti")
.HasForeignKey("GroupID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GradeBookServer.Domain.Entities.User", "Professor")
.WithMany("Vedomosti")
.HasForeignKey("ProfessorID");
b.Navigation("Discipline");
b.Navigation("Group");
b.Navigation("Professor");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Direction", b =>
{
b.Navigation("Groups");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Discipline", b =>
{
b.Navigation("Vedomosti");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Faculty", b =>
{
b.Navigation("Directions");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Group", b =>
{
b.Navigation("Students");
b.Navigation("Vedomosti");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Student", b =>
{
b.Navigation("Grades");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.User", b =>
{
b.Navigation("Vedomosti");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Vedomost", b =>
{
b.Navigation("Grades");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,285 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace GradeBookServer.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AllBD : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Disciplines",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
TotalHours = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Disciplines", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Faculties",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Faculties", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
PhoneNumber = table.Column<string>(type: "text", nullable: true),
Password = table.Column<string>(type: "text", nullable: false),
Role = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Directions",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
FacultyID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Directions", x => x.ID);
table.ForeignKey(
name: "FK_Directions_Faculties_FacultyID",
column: x => x.FacultyID,
principalTable: "Faculties",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "DirectionDiscipline",
columns: table => new
{
DirectionsID = table.Column<int>(type: "integer", nullable: false),
DisciplinesID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DirectionDiscipline", x => new { x.DirectionsID, x.DisciplinesID });
table.ForeignKey(
name: "FK_DirectionDiscipline_Directions_DirectionsID",
column: x => x.DirectionsID,
principalTable: "Directions",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_DirectionDiscipline_Disciplines_DisciplinesID",
column: x => x.DisciplinesID,
principalTable: "Disciplines",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Groups",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
DirectionID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Groups", x => x.ID);
table.ForeignKey(
name: "FK_Groups_Directions_DirectionID",
column: x => x.DirectionID,
principalTable: "Directions",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FullName = table.Column<string>(type: "text", nullable: false),
Age = table.Column<int>(type: "integer", nullable: false),
GroupID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Students", x => x.ID);
table.ForeignKey(
name: "FK_Students_Groups_GroupID",
column: x => x.GroupID,
principalTable: "Groups",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Vedomosti",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ExamType = table.Column<int>(type: "integer", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false),
AcademicYear = table.Column<DateOnly>(type: "date", nullable: false),
Semester = table.Column<int>(type: "integer", nullable: false),
Hours = table.Column<int>(type: "integer", nullable: false),
GroupID = table.Column<int>(type: "integer", nullable: false),
DisciplineID = table.Column<int>(type: "integer", nullable: false),
ProfessorID = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Vedomosti", x => x.ID);
table.ForeignKey(
name: "FK_Vedomosti_Disciplines_DisciplineID",
column: x => x.DisciplineID,
principalTable: "Disciplines",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Vedomosti_Groups_GroupID",
column: x => x.GroupID,
principalTable: "Groups",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Vedomosti_Users_ProfessorID",
column: x => x.ProfessorID,
principalTable: "Users",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Grades",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StudentID = table.Column<int>(type: "integer", nullable: false),
VedomostID = table.Column<int>(type: "integer", nullable: false),
GradeValue = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Grades", x => x.ID);
table.ForeignKey(
name: "FK_Grades_Students_StudentID",
column: x => x.StudentID,
principalTable: "Students",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Grades_Vedomosti_VedomostID",
column: x => x.VedomostID,
principalTable: "Vedomosti",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_DirectionDiscipline_DisciplinesID",
table: "DirectionDiscipline",
column: "DisciplinesID");
migrationBuilder.CreateIndex(
name: "IX_Directions_FacultyID",
table: "Directions",
column: "FacultyID");
migrationBuilder.CreateIndex(
name: "IX_Grades_StudentID",
table: "Grades",
column: "StudentID");
migrationBuilder.CreateIndex(
name: "IX_Grades_VedomostID",
table: "Grades",
column: "VedomostID");
migrationBuilder.CreateIndex(
name: "IX_Groups_DirectionID",
table: "Groups",
column: "DirectionID");
migrationBuilder.CreateIndex(
name: "IX_Students_GroupID",
table: "Students",
column: "GroupID");
migrationBuilder.CreateIndex(
name: "IX_Vedomosti_DisciplineID",
table: "Vedomosti",
column: "DisciplineID");
migrationBuilder.CreateIndex(
name: "IX_Vedomosti_GroupID",
table: "Vedomosti",
column: "GroupID");
migrationBuilder.CreateIndex(
name: "IX_Vedomosti_ProfessorID",
table: "Vedomosti",
column: "ProfessorID");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DirectionDiscipline");
migrationBuilder.DropTable(
name: "Grades");
migrationBuilder.DropTable(
name: "Students");
migrationBuilder.DropTable(
name: "Vedomosti");
migrationBuilder.DropTable(
name: "Disciplines");
migrationBuilder.DropTable(
name: "Groups");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Directions");
migrationBuilder.DropTable(
name: "Faculties");
}
}
}

View File

@@ -0,0 +1,377 @@
// <auto-generated />
using System;
using GradeBookServer.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace GradeBookServer.Infrastructure.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.5")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DirectionDiscipline", b =>
{
b.Property<int>("DirectionsID")
.HasColumnType("integer");
b.Property<int>("DisciplinesID")
.HasColumnType("integer");
b.HasKey("DirectionsID", "DisciplinesID");
b.HasIndex("DisciplinesID");
b.ToTable("DirectionDiscipline");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Direction", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<int>("FacultyID")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("FacultyID");
b.ToTable("Directions");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Discipline", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("TotalHours")
.HasColumnType("integer");
b.HasKey("ID");
b.ToTable("Disciplines");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Faculty", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.ToTable("Faculties");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Grade", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<int>("GradeValue")
.HasColumnType("integer");
b.Property<int>("StudentID")
.HasColumnType("integer");
b.Property<int>("VedomostID")
.HasColumnType("integer");
b.HasKey("ID");
b.HasIndex("StudentID");
b.HasIndex("VedomostID");
b.ToTable("Grades");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Group", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<int>("DirectionID")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("ID");
b.HasIndex("DirectionID");
b.ToTable("Groups");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Student", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<int>("Age")
.HasColumnType("integer");
b.Property<string>("FullName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("GroupID")
.HasColumnType("integer");
b.HasKey("ID");
b.HasIndex("GroupID");
b.ToTable("Students");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<int>("Role")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Vedomost", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ID"));
b.Property<DateOnly>("AcademicYear")
.HasColumnType("date");
b.Property<int>("DisciplineID")
.HasColumnType("integer");
b.Property<int>("ExamType")
.HasColumnType("integer");
b.Property<int>("GroupID")
.HasColumnType("integer");
b.Property<int>("Hours")
.HasColumnType("integer");
b.Property<int?>("ProfessorID")
.HasColumnType("integer");
b.Property<int>("Semester")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.HasKey("ID");
b.HasIndex("DisciplineID");
b.HasIndex("GroupID");
b.HasIndex("ProfessorID");
b.ToTable("Vedomosti");
});
modelBuilder.Entity("DirectionDiscipline", b =>
{
b.HasOne("GradeBookServer.Domain.Entities.Direction", null)
.WithMany()
.HasForeignKey("DirectionsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GradeBookServer.Domain.Entities.Discipline", null)
.WithMany()
.HasForeignKey("DisciplinesID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Direction", b =>
{
b.HasOne("GradeBookServer.Domain.Entities.Faculty", "Faculty")
.WithMany("Directions")
.HasForeignKey("FacultyID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Faculty");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Grade", b =>
{
b.HasOne("GradeBookServer.Domain.Entities.Student", "Student")
.WithMany("Grades")
.HasForeignKey("StudentID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GradeBookServer.Domain.Entities.Vedomost", "Vedomost")
.WithMany("Grades")
.HasForeignKey("VedomostID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Student");
b.Navigation("Vedomost");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Group", b =>
{
b.HasOne("GradeBookServer.Domain.Entities.Direction", "Direction")
.WithMany("Groups")
.HasForeignKey("DirectionID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Direction");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Student", b =>
{
b.HasOne("GradeBookServer.Domain.Entities.Group", "Group")
.WithMany("Students")
.HasForeignKey("GroupID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Group");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Vedomost", b =>
{
b.HasOne("GradeBookServer.Domain.Entities.Discipline", "Discipline")
.WithMany("Vedomosti")
.HasForeignKey("DisciplineID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GradeBookServer.Domain.Entities.Group", "Group")
.WithMany("Vedomosti")
.HasForeignKey("GroupID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("GradeBookServer.Domain.Entities.User", "Professor")
.WithMany("Vedomosti")
.HasForeignKey("ProfessorID");
b.Navigation("Discipline");
b.Navigation("Group");
b.Navigation("Professor");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Direction", b =>
{
b.Navigation("Groups");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Discipline", b =>
{
b.Navigation("Vedomosti");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Faculty", b =>
{
b.Navigation("Directions");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Group", b =>
{
b.Navigation("Students");
b.Navigation("Vedomosti");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Student", b =>
{
b.Navigation("Grades");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.User", b =>
{
b.Navigation("Vedomosti");
});
modelBuilder.Entity("GradeBookServer.Domain.Entities.Vedomost", b =>
{
b.Navigation("Grades");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,64 @@
using GradeBookServer.Application.Interfaces;
using GradeBookServer.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace GradeBookServer.Infrastructure.Repositories
{
public class BaseRepository<TEntity> : IBaseRepository<TEntity> where TEntity : class
{
protected readonly DbContext _context;
protected readonly DbSet<TEntity> _dbSet;
public BaseRepository(DbContext context)
{
_context = context;
_dbSet = context.Set<TEntity>();
}
public virtual async Task<TEntity?> GetByIdAsync(int id)
=> await _dbSet.FindAsync(id);
public virtual async Task AddAsync(TEntity entity)
{
await _dbSet.AddAsync(entity);
await _context.SaveChangesAsync();
}
public virtual async Task<IEnumerable<TEntity>?> GetAllAsync()
=> await _dbSet.ToListAsync();
public virtual async Task UpdateAsync(TEntity entity)
{
_dbSet.Update(entity);
await _context.SaveChangesAsync();
}
public virtual async Task DeleteAsync(int id)
{
var entity = await _dbSet.FindAsync(id);
if (entity != null)
{
_dbSet.Remove(entity);
await _context.SaveChangesAsync();
}
}
public async Task<TEntity?> GetByIdWithIncludeAsync
(int id, Expression<Func<TEntity, bool>> idSelector, params Expression<Func<TEntity, object>>[] includes)
{
IQueryable<TEntity> query = _dbSet;
foreach (var include in includes)
query = query.Include(include);
return await query.FirstOrDefaultAsync(idSelector);
}
}
}

View File

@@ -0,0 +1,61 @@
// WebAPI/Controllers/StudentController.cs
using GradeBookServer.Application.DTOs.Student;
using GradeBookServer.Application.Services;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace WebAPI.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class StudentController : ControllerBase
{
private readonly StudentService _studentService;
public StudentController(StudentService studentService)
{
_studentService = studentService;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<StudentTableDto>>> GetAllStudents()
{
var students = await _studentService.GetAllStudentsAsync();
return Ok(students);
}
[HttpGet("{id}")]
public async Task<ActionResult<StudentReadDto>> GetStudentById(int id)
{
var student = await _studentService.GetStudentByIdAsync(id);
if (student == null)
{
return NotFound();
}
return Ok(student);
}
[HttpPost]
public async Task<ActionResult> AddStudent([FromBody] StudentCreateDto studentDto)
{
await _studentService.AddStudentAsync(studentDto);
return CreatedAtAction(nameof(GetStudentById), studentDto);
}
[HttpPut("{id}")]
public async Task<ActionResult> UpdateStudent(int id, [FromBody] StudentCreateDto studentDto)
{
await _studentService.UpdateStudentAsync(id, studentDto);
return NoContent();
}
[HttpDelete("{id}")]
public async Task<ActionResult> DeleteStudent(int id)
{
await _studentService.DeleteStudentAsync(id);
return NoContent();
}
}
}

View File

@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GradeBookServer.Application\GradeBookServer.Application.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GradeBookServer.Domain\GradeBookServer.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GradeBookServer.Infrastructure\GradeBookServer.Infrastructure.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,6 @@
@GradeBookServer.WebAPI_HostAddress = http://localhost:5142
GET {{GradeBookServer.WebAPI_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.35931.197 d17.13
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GradeBookServer.WebAPI", "GradeBookServer.WebAPI.csproj", "{8AEE9485-A46E-4145-A1FE-1B280E8C4561}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GradeBookServer.Domain", "..\GradeBookServer.Domain\GradeBookServer.Domain.csproj", "{2B4DE2E5-F5A1-4FDC-B67C-022438E0584E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GradeBookServer.Application", "..\GradeBookServer.Application\GradeBookServer.Application.csproj", "{3E6FBCC4-9EA3-4A7C-A2A9-50EE4B80757A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GradeBookServer.Infrastructure", "..\GradeBookServer.Infrastructure\GradeBookServer.Infrastructure.csproj", "{4477C8C0-F545-455E-81A1-576551006D03}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8AEE9485-A46E-4145-A1FE-1B280E8C4561}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8AEE9485-A46E-4145-A1FE-1B280E8C4561}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8AEE9485-A46E-4145-A1FE-1B280E8C4561}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8AEE9485-A46E-4145-A1FE-1B280E8C4561}.Release|Any CPU.Build.0 = Release|Any CPU
{2B4DE2E5-F5A1-4FDC-B67C-022438E0584E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B4DE2E5-F5A1-4FDC-B67C-022438E0584E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B4DE2E5-F5A1-4FDC-B67C-022438E0584E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B4DE2E5-F5A1-4FDC-B67C-022438E0584E}.Release|Any CPU.Build.0 = Release|Any CPU
{3E6FBCC4-9EA3-4A7C-A2A9-50EE4B80757A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E6FBCC4-9EA3-4A7C-A2A9-50EE4B80757A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E6FBCC4-9EA3-4A7C-A2A9-50EE4B80757A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E6FBCC4-9EA3-4A7C-A2A9-50EE4B80757A}.Release|Any CPU.Build.0 = Release|Any CPU
{4477C8C0-F545-455E-81A1-576551006D03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4477C8C0-F545-455E-81A1-576551006D03}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4477C8C0-F545-455E-81A1-576551006D03}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4477C8C0-F545-455E-81A1-576551006D03}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C5267331-1AD7-4C07-B032-18F3D9B9B467}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,55 @@
using GradeBookServer.Application.Interfaces;
using GradeBookServer.Application.Services;
using GradeBookServer.Infrastructure.Data;
using GradeBookServer.Infrastructure.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo
{
Version = "1.0.0",
Title = "YumAsia API",
Description = "API <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
});
});
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
builder.Services.AddScoped<DbContext, ApplicationDbContext>();
builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));
builder.Services.AddScoped<StudentService>();
builder.Services.AddControllers();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "YumAsia API V1");
});
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8634",
"sslPort": 44300
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5142",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7270;http://localhost:5142",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,12 @@
{
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Port=5432;Database=YumAsiaDb;Username=postgres;Password=postgres"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}