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

60 lines
1.6 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 string MedicinesName { get; private set; } = string.Empty;
[Required]
public string Group { get; private set; } = string.Empty;
public static Medicines? Create(MedicinesBindingModel model)
{
if (model == null)
{
return null;
}
return new Medicines()
{
Id = model.Id,
MedicinesName = model.MedicinesName,
Group = model.Group
};
}
public static Medicines Create(MedicinesViewModel model)
{
return new Medicines
{
Id = model.Id,
MedicinesName = model.MedicinesName,
Group = model.Group
};
}
public void Update(MedicinesBindingModel model)
{
if (model == null)
{
return;
}
MedicinesName = model.MedicinesName;
Group = model.Group;
}
public MedicinesViewModel GetViewModel => new()
{
Id = Id,
MedicinesName = MedicinesName,
Group = Group
};
}
}