Rogashova_E.A._CourseWork_H.../HospitalDataBaseImplements/Models/Medicines.cs

74 lines
2.2 KiB
C#

using HospitalContracts.BindingModels;
using HospitalContracts.ViewModels;
using HospitalDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalDataBaseImplements.Models
{
public class Medicines : IMedicinesModel
{
public int Id { get; private set; }
[Required]
public int ClientId { get; private set; }
[Required]
public string MedicinesName { get; private set; } = string.Empty;
[Required]
public string Group { get; private set; } = string.Empty;
public virtual Client Client { get; set; }
[ForeignKey("MedicineId")]
public virtual List<ProcedureMedicine> Procedures { get; set; } = new();
[ForeignKey("MedicineId")]
public virtual List<KurseMedicines> KurseMedicines { get; set; } = new();
public static Medicines? Create(MedicinesBindingModel model)
{
if (model == null)
{
return null;
}
return new Medicines()
{
Id = model.Id,
ClientId = model.ClientId,
MedicinesName = model.MedicinesName,
Group = model.Group
};
}
public static Medicines Create(MedicinesViewModel model)
{
return new Medicines
{
Id = model.Id,
ClientId = model.ClientId,
MedicinesName = model.MedicinesName,
Group = model.Group
};
}
public void Update(MedicinesBindingModel model)
{
if (model == null)
{
return;
}
MedicinesName = model.MedicinesName;
Group = model.Group;
ClientId = model.ClientId;
}
public MedicinesViewModel GetViewModel => new()
{
Id = Id,
ClientId = ClientId,
MedicinesName = MedicinesName,
Group = Group
};
}
}