PIbd-21_Pyatakov_KM_Markov_.../UniversityDataBaseImplemet/Models/Discipline.cs
2023-04-08 13:59:34 +04:00

67 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityModels.Models;
namespace UniversityDataBaseImplemet.Models
{
public class Discipline : IDisciplineModel
{
public int Id { get; private set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public int UserId { get; set; }
[Required]
public int StreamId { get; set; }
[Required]
public int Hours { get; set; }
[Required]
public bool MarkType { get; set; }
public virtual Stream Stream { get; set; }
public virtual User User { get; set; }
public static Discipline? Create(DisciplineBindingModel model)
{
return new Discipline()
{
Id = model.Id,
Name = model.Name,
UserId = model.UserId,
StreamId = model.StreamId,
Hours= model.Hours,
MarkType = model.MarkType
};
}
public void Update(DisciplineBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
UserId = model.UserId;
StreamId = model.StreamId;
Hours = model.Hours;
MarkType = model.MarkType;
}
public DisciplineViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
UserId = UserId,
StreamId = StreamId,
Hours = Hours,
MarkType = MarkType
};
}
}