forked from DavidMakarov/StudentEnrollment
51 lines
1.2 KiB
C#
51 lines
1.2 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
|
|
{
|
|
[Key]
|
|
public int course_id { get; private set; }
|
|
[Required]
|
|
public string name { get; private set; } = string.Empty;
|
|
[Required]
|
|
public int facultyid { get; set; }
|
|
public virtual Faculty Faculty { get; 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()
|
|
{
|
|
course_id = model.course_id,
|
|
name = model.name,
|
|
facultyid = model.facultyid,
|
|
};
|
|
}
|
|
public void Update(CourseBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
name = model.name;
|
|
facultyid = model.facultyid;
|
|
}
|
|
public CourseViewModel GetViewModel => new()
|
|
{
|
|
course_id = course_id,
|
|
name = name,
|
|
facultyid = facultyid,
|
|
FacultyName = Faculty.name,
|
|
};
|
|
}
|
|
}
|