82 lines
2.1 KiB
C#
82 lines
2.1 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 HospitalDataModels.Models;
|
|
using HospitalContracts.BindingModels;
|
|
using HospitalContracts.ViewModels;
|
|
|
|
namespace HospitalDataBaseImplements.Models
|
|
{
|
|
public class Kurses : IKurseModel
|
|
{
|
|
public int Id { get; private set; }
|
|
[Required]
|
|
public string Duration { get; private set; } = string.Empty;
|
|
[Required]
|
|
public int CountInDay { get; private set; }
|
|
[ForeignKey("KurseId")]
|
|
|
|
public virtual List<IllnessKurse> IllnessKurses { get; set; } = new();
|
|
|
|
private Dictionary<int, IMedicinesModel>? _kurseMedicine = null;
|
|
|
|
[NotMapped]
|
|
public Dictionary<int, IMedicinesModel> KurseMedicine
|
|
{
|
|
get
|
|
{
|
|
if (_kurseMedicine == null)
|
|
{
|
|
_kurseMedicine = Medicines
|
|
.ToDictionary(rec => rec.MedicineId, rec =>
|
|
rec.Medicine as IMedicinesModel);
|
|
}
|
|
return _kurseMedicine;
|
|
}
|
|
}
|
|
[ForeignKey("KurseId")]
|
|
public virtual List<KurseMedicines> Medicines { get; set; } = new();
|
|
public static Kurses? Create(KurseBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Kurses()
|
|
{
|
|
Id = model.Id,
|
|
Duration = model.Duration,
|
|
CountInDay = model.CountInDay
|
|
};
|
|
}
|
|
public static Kurses Create(KurseViewModel model)
|
|
{
|
|
return new Kurses
|
|
{
|
|
Id = model.Id,
|
|
Duration = model.Duration,
|
|
CountInDay = model.CountInDay
|
|
};
|
|
}
|
|
public void Update(KurseBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
Duration = model.Duration;
|
|
CountInDay = model.CountInDay;
|
|
}
|
|
public KurseViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Duration = Duration,
|
|
CountInDay = CountInDay
|
|
};
|
|
}
|
|
}
|