forked from DavidMakarov/StudentEnrollment
50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
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,
|
|
};
|
|
}
|
|
}
|