CourseWork_SchoolStudyAgain/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Models/Interest.cs

66 lines
1.8 KiB
C#
Raw Normal View History

using SchoolAgainStudyContracts.BindingModel;
using SchoolAgainStudyContracts.ViewModel;
using SchoolAgainStudyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolAgainStudyDataBaseImplements.Models
{
public class Interest : IInterest
{
[Required]
public string Title { get; set; } = string.Empty;
[Required]
public string Description { get; set; } = string.Empty;
public int Id { get; set; }
[Required]
public int StudentId { get; set; }
public virtual Student Student { get; set; }
[ForeignKey("InterestId")]
public virtual List<DiyInterest> DiyInterests { get; set; } = new();
[ForeignKey("InterestId")]
public virtual List<ProductInterest> ProductInterests { get; set; } = new();
public static Interest? Create(InterestBindingModel model)
{
if (model == null)
{
return null;
}
return new Interest()
{
Id = model.Id,
Title = model.Title,
Description = model.Description,
StudentId = model.StudentId,
};
}
public void Update(InterestBindingModel model)
{
if (model == null)
{
return;
}
Title = model.Title;
Description = model.Description;
}
public InterestViewModel GetViewModel => new()
{
Id = Id,
Title = Title,
Description = Description,
StudentId = StudentId,
};
}
}