forked from DavidMakarov/StudentEnrollment
implement 3.8 of 5 projects (remain View and DatabaseImplement.Implemets)
This commit is contained in:
parent
5f67d6dc8a
commit
4958e973bc
@ -34,7 +34,7 @@ namespace StudentEnrollmentBusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadList. TIN: {TIN}. Id:{Id}", model?.TIN, model.Id);
|
||||
_logger.LogInformation("ReadList. TIN: {TIN}. Id:{Id}", model?.TIN, model?.Id);
|
||||
var element = _studentStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
|
@ -6,6 +6,6 @@ namespace StudentEnrollmentContracts.BindingModels
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string CourseName { get; set; } = string.Empty;
|
||||
public string FacultyName { get; set; } = string.Empty;
|
||||
public long FacultyId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace StudentEnrollmentContracts.BindingModels
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string TIN { get; set; } = string.Empty;
|
||||
public long ExamPointsId { get; set; }
|
||||
public Dictionary<long, (ICourseModel, long)> StudentCourse
|
||||
public Dictionary<long, ICourseModel> StudentCourse
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -10,5 +10,6 @@ namespace StudentEnrollmentContracts.ViewModels
|
||||
public string CourseName { get; set; } = string.Empty;
|
||||
[DisplayName("Название факультета")]
|
||||
public string FacultyName { get; set; } = string.Empty;
|
||||
public long FacultyId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ namespace StudentEnrollmentContracts.ViewModels
|
||||
public long ExamPointsId { get; set; }
|
||||
[DisplayName("Суммарное количество баллов")]
|
||||
public int ExamPoints { get; set; }
|
||||
public Dictionary<long, (ICourseModel, long)> StudentCourse
|
||||
public Dictionary<long, ICourseModel> StudentCourse
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -3,6 +3,6 @@
|
||||
public interface ICourseModel : IId
|
||||
{
|
||||
string CourseName { get; }
|
||||
string FacultyName { get; }
|
||||
long FacultyId { get; }
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,6 @@
|
||||
string Email { get; }
|
||||
string TIN { get; }
|
||||
long ExamPointsId { get; }
|
||||
Dictionary<long, (ICourseModel, long)> StudentCourse { get; }
|
||||
Dictionary<long, ICourseModel> StudentCourse { get; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
using StudentEnrollmentContracts.StorageContracts;
|
||||
|
||||
namespace StudentEnrollmentDatabaseImplement.Implements
|
||||
{
|
||||
public class CourseStorage : ICourseStorage
|
||||
{
|
||||
// TODO: Implement this
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
using StudentEnrollmentContracts.StorageContracts;
|
||||
|
||||
namespace StudentEnrollmentDatabaseImplement.Implements
|
||||
{
|
||||
public class ExamPoints : IExamPointsStorage
|
||||
{
|
||||
// TODO: Implement this
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using StudentEnrollmentContracts.BindingModels;
|
||||
using StudentEnrollmentContracts.SearchModels;
|
||||
using StudentEnrollmentContracts.StorageContracts;
|
||||
using StudentEnrollmentContracts.ViewModels;
|
||||
|
||||
namespace StudentEnrollmentDatabaseImplement.Implements
|
||||
{
|
||||
public class FacultyStorage : IFacultyStorage
|
||||
{
|
||||
// TODO: Implement this
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
using StudentEnrollmentContracts.StorageContracts;
|
||||
|
||||
namespace StudentEnrollmentDatabaseImplement.Implements
|
||||
{
|
||||
public class StudentStorage : IStudentStorage
|
||||
{
|
||||
// TODO: Implement this
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
using StudentEnrollmentContracts.BindingModels;
|
||||
using StudentEnrollmentContracts.ViewModels;
|
||||
using StudentEnrollmentDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace StudentEnrollmentDatabaseImplement.Models
|
||||
{
|
||||
public class Course : ICourseModel
|
||||
{
|
||||
public long Id { get; private set; }
|
||||
[Required]
|
||||
public string CourseName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public long FacultyId { get; private set; }
|
||||
|
||||
[ForeignKey("CourseId")]
|
||||
public virtual List<StudentCourse> StudentCourses { get; set; } = new();
|
||||
|
||||
public static Course? Create(CourseBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Course()
|
||||
{
|
||||
Id = model.Id,
|
||||
CourseName = model.CourseName,
|
||||
FacultyId = model.FacultyId,
|
||||
};
|
||||
}
|
||||
public void Update(CourseBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CourseName = model.CourseName;
|
||||
FacultyId = model.FacultyId;
|
||||
}
|
||||
public CourseViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
CourseName = CourseName,
|
||||
FacultyId = FacultyId,
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
using StudentEnrollmentContracts.BindingModels;
|
||||
using StudentEnrollmentDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace StudentEnrollmentDatabaseImplement.Models
|
||||
{
|
||||
public class ExamPoints : IExamPointsModel
|
||||
{
|
||||
public long Id { get; private set; }
|
||||
[Required]
|
||||
public int FirstExamPoints { get; private set; }
|
||||
[Required]
|
||||
public int SecondExamPoints { get; private set; }
|
||||
[Required]
|
||||
public int ThirdExamPoints { get; private set; }
|
||||
public int AddPoints { get; private set; }
|
||||
public int Summary { get; private set; }
|
||||
public static ExamPoints? Create(ExamPointsBindingModel model)
|
||||
{
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return new ExamPoints()
|
||||
{
|
||||
Id = model.Id,
|
||||
FirstExamPoints = model.FirstExamPoints,
|
||||
SecondExamPoints = model.SecondExamPoints,
|
||||
ThirdExamPoints = model.ThirdExamPoints,
|
||||
AddPoints = model.AddPoints,
|
||||
Summary = model.Summary,
|
||||
};
|
||||
}
|
||||
public void Update(ExamPointsBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
AddPoints = model.AddPoints;
|
||||
Summary = model.Summary;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using StudentEnrollmentContracts.BindingModels;
|
||||
using StudentEnrollmentContracts.ViewModels;
|
||||
using StudentEnrollmentDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace StudentEnrollmentDatabaseImplement.Models
|
||||
{
|
||||
public class Faculty : IFacultyModel
|
||||
{
|
||||
public long Id { get; private set; }
|
||||
[Required]
|
||||
public string FacultyName { get; private set;} = string.Empty;
|
||||
public static Faculty? Create(FacultyBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
return new Faculty()
|
||||
{
|
||||
Id = model.Id,
|
||||
FacultyName = model.FacultyName,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(FacultyBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
return;
|
||||
FacultyName = model.FacultyName;
|
||||
}
|
||||
|
||||
public FacultyViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
FacultyName = FacultyName,
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
using StudentEnrollmentContracts.BindingModels;
|
||||
using StudentEnrollmentDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace StudentEnrollmentDatabaseImplement.Models
|
||||
{
|
||||
public class Student : IStudentModel
|
||||
{
|
||||
public long Id { get; private set; }
|
||||
[Required]
|
||||
public string FirstName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string LastName { get; private set; } = string.Empty;
|
||||
public string MiddleName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string TIN { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public long ExamPointsId { get; private set; }
|
||||
private Dictionary<long, ICourseModel>? _StudentCourse = null;
|
||||
public Dictionary<long, ICourseModel> StudentCourse
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_StudentCourse == null)
|
||||
{
|
||||
_StudentCourse = Courses.ToDictionary(SC => SC.CourseId,
|
||||
SC => SC.Course as ICourseModel);
|
||||
}
|
||||
return _StudentCourse;
|
||||
}
|
||||
}
|
||||
[ForeignKey("StudentId")]
|
||||
public virtual List<StudentCourse> Courses { get; set; } = new();
|
||||
|
||||
public static Student? Create(StudentEnrollmentDatabase context,StudentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Student()
|
||||
{
|
||||
Id = model.Id,
|
||||
FirstName = model.FirstName,
|
||||
LastName = model.LastName,
|
||||
MiddleName = model.MiddleName,
|
||||
Email = model.Email,
|
||||
TIN = model.TIN,
|
||||
Courses = model.StudentCourse.Select(x => new StudentCourse
|
||||
{
|
||||
Course = context.Courses.First(y => y.Id == x.Key)
|
||||
}
|
||||
).ToList(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace StudentEnrollmentDatabaseImplement.Models
|
||||
{
|
||||
public class StudentCourse
|
||||
{
|
||||
public long Id { get; set; }
|
||||
[Required]
|
||||
public long StudentId { get; set; }
|
||||
[Required]
|
||||
public long CourseId { get; set; }
|
||||
public virtual Student Student { get; set; } = new();
|
||||
public virtual Course Course { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using StudentEnrollmentDatabaseImplement.Models;
|
||||
|
||||
namespace StudentEnrollmentDatabaseImplement
|
||||
{
|
||||
public class StudentEnrollmentDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseNpgsql(@"Host=localhost;Database=StudentEnrollmentDatabase;Username=postgres;Password=postgres");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
AppContext.SetSwitch("Npgsql.DisableDataTimeInfinityConversions", true);
|
||||
}
|
||||
public virtual DbSet<Faculty> Faculties { get; set; }
|
||||
public virtual DbSet<Course> Courses { get; set; }
|
||||
public virtual DbSet<Student> Students { get; set; }
|
||||
public virtual DbSet<StudentCourse> StudentCourses { get; set; }
|
||||
public virtual DbSet<ExamPoints> ExamPointes { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -6,4 +6,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Implements\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\StudentEnrollmentContracts\StudentEnrollmentContracts.csproj" />
|
||||
<ProjectReference Include="..\StudentEnrollmentDataModels\StudentEnrollmentDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user