64 lines
1.7 KiB
C#
64 lines
1.7 KiB
C#
|
using SecureShopContracts.BindingModels;
|
|||
|
using SecureShopContracts.ViewModels;
|
|||
|
using SecureShopDataModels.Models;
|
|||
|
using System.ComponentModel.DataAnnotations;
|
|||
|
using System.ComponentModel.DataAnnotations.Schema;
|
|||
|
|
|||
|
namespace SecureShopDatabaseImplement.Models
|
|||
|
{
|
|||
|
public class Facilities : IFacilitiesModel
|
|||
|
{
|
|||
|
public int Id { get; private set; }
|
|||
|
|
|||
|
[Required]
|
|||
|
public string FacilitiesName { get; private set; } = string.Empty;
|
|||
|
|
|||
|
[Required]
|
|||
|
public double Cost { get; set; }
|
|||
|
|
|||
|
[ForeignKey("FacilitiesId")]
|
|||
|
public virtual List<SecureFacilities> SecureFacilitiess { get; set; } = new();
|
|||
|
|
|||
|
public static Facilities? Create(FacilitiesBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new Facilities()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
FacilitiesName = model.FacilitiesName,
|
|||
|
Cost = model.Cost
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public static Facilities Create(FacilitiesViewModel model)
|
|||
|
{
|
|||
|
return new Facilities
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
FacilitiesName = model.FacilitiesName,
|
|||
|
Cost = model.Cost
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public void Update(FacilitiesBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
FacilitiesName = model.FacilitiesName;
|
|||
|
Cost = model.Cost;
|
|||
|
}
|
|||
|
|
|||
|
public FacilitiesViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id,
|
|||
|
FacilitiesName = FacilitiesName,
|
|||
|
Cost = Cost
|
|||
|
};
|
|||
|
}
|
|||
|
}
|