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

64 lines
1.9 KiB
C#

using PolyclinicContracts.BindingModels;
using PolyclinicContracts.ViewModels;
using PolyclinicDataModels.Models;
using System.ComponentModel.DataAnnotations;
namespace PolyclinicDatabaseImplement.Models
{
public class Procedure : IProcedureModel
{
public int Id { get; set; }
[Required]
public int UserId { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public DateTime DateStartProcedure { get; set; } = DateTime.Now;
public DateTime? DateStopProcedure { get; set; }
public virtual User? User { get; set; }
public string? Comment { get; set; } = string.Empty;
public static Procedure? Create(ProcedureBindingModel bindingModel)
{
if (bindingModel == null) return null;
return new Procedure()
{
Id = bindingModel.Id,
UserId = bindingModel.UserId,
Name = bindingModel.Name,
Comment = bindingModel.Comment,
DateStartProcedure = bindingModel.DateStartProcedure,
DateStopProcedure = bindingModel.DateStopProcedure,
};
}
public void Update(ProcedureBindingModel? bindingModel)
{
if (bindingModel == null)
{
return;
}
Name = bindingModel.Name;
Comment = bindingModel.Comment;
DateStartProcedure = bindingModel.DateStartProcedure;
DateStopProcedure = bindingModel.DateStopProcedure;
}
public ProcedureViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
UserId = UserId,
Comment = Comment,
DateStartProcedure = DateStartProcedure,
DateStopProcedure = DateStopProcedure,
};
}
}