PIbd-21_CourseWork_Polyclin.../Polyclinic/PolyclinicDatabaseImplement/Models/Diagnose.cs

62 lines
1.8 KiB
C#

using PolyclinicContracts.BindingModels;
using PolyclinicContracts.ViewModels;
using PolyclinicDataModels.Models;
using System.ComponentModel.DataAnnotations;
namespace PolyclinicDatabaseImplement.Models
{
public class Diagnose : IDiagnoseModel
{
[Required]
public string Name { get; set; } = string.Empty;
public string? Comment { get; set; }
[Required]
public int UserId { get; set; }
[Required]
public DateTime DateStartDiagnose { get; set; } = DateTime.Now;
public DateTime? DateStopDiagnose { get; set; }
public int Id { get; set; }
public virtual User? User { get; set; }
public static Diagnose? Create(DiagnoseBindingModel? model)
{
if (model == null)
{
return null;
}
return new Diagnose
{
Name = model.Name,
Comment = model.Comment,
UserId = model.UserId,
Id = model.Id,
DateStartDiagnose = model.DateStartDiagnose,
DateStopDiagnose = model.DateStopDiagnose,
};
}
public void Update(DiagnoseBindingModel? model)
{
if (model == null)
{
return;
}
Name = model.Name;
Comment = model.Comment;
DateStartDiagnose = model.DateStartDiagnose;
DateStopDiagnose = model.DateStopDiagnose;
}
public DiagnoseViewModel GetViewModel => new()
{
Name = Name,
Comment = Comment,
UserId = UserId,
Id = Id,
DateStartDiagnose = DateStartDiagnose,
DateStopDiagnose = DateStopDiagnose,
};
}
}