SUBD_Labs/BeautySalonDatabaseImplement/Models/Service.cs

57 lines
1.6 KiB
C#

using BeautySalonContracts.BindingModels;
using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace BeautySalonDatabaseImplement.Models
{
public class Service : IServiceModel
{
public int Id { get; private set; }
[Required]
public string ServiceName { get; private set; } = string.Empty;
[Required]
public double Cost { get; set; }
[ForeignKey("ServiceId")]
public virtual List<MasterService> MasterServices { get; set; } = new();
public static Service? Create(ServiceBindingModel model)
{
if (model == null)
{
return null;
}
return new Service()
{
Id = model.Id,
ServiceName = model.ServiceName,
Cost = model.Cost
};
}
public static Service Create(ServiceViewModel model)
{
return new Service
{
Id = model.Id,
ServiceName = model.ServiceName,
Cost = model.Cost
};
}
public void Update(ServiceBindingModel model)
{
if (model == null)
{
return;
}
ServiceName = model.ServiceName;
Cost = model.Cost;
}
public ServiceViewModel GetViewModel => new()
{
Id = Id,
ServiceName = ServiceName,
Cost = Cost
};
}
}