SUBD_Labs/BeautySalonDatabaseImplement/Models/Visit.cs

78 lines
2.4 KiB
C#

using BeautySalonContracts.BindingModels;
using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Models;
using System.ComponentModel.DataAnnotations;
namespace BeautySalonDatabaseImplement.Models
{
public class Visit : IVisitModel
{
public int Id { get; private set; }
[Required]
public DateTime DateOfVisit { get; private set; }
[Required]
public int ClientId { get; private set; }
public int MasterId { get; private set; }
public int ServiceId { get; private set; }
public string ClientFIO { get; set; } = string.Empty;
public string MasterFIO { get; set; } = string.Empty;
public string ServiceName { get; set; } = string.Empty;
[Required]
public double Sum { get; private set; }
public virtual Client Client { get; set; }
public virtual Master Master { get; set; }
public virtual Service Service { get; set; }
public static Visit? Create(VisitBindingModel? model)
{
if (model == null)
{
return null;
}
return new Visit()
{
Id = model.Id,
ClientId = model.ClientId,
ClientFIO = model.ClientFIO,
MasterId = model.MasterId,
MasterFIO = model.MasterFIO,
ServiceId = model.ServiceId,
ServiceName = model.ServiceName,
Sum = model.Sum,
DateOfVisit = model.DateOfVisit
};
}
public void Update(VisitBindingModel? model)
{
if (model == null)
{
return;
}
ClientId = model.ClientId;
ClientFIO = model.ClientFIO;
MasterId = model.MasterId;
MasterFIO = model.MasterFIO;
ServiceId = model.ServiceId;
ServiceName = model.ServiceName;
Sum = model.Sum;
DateOfVisit = model.DateOfVisit;
}
public VisitViewModel GetViewModel => new()
{
Id = Id,
ClientId = ClientId,
ClientFIO = ClientFIO,
MasterId = MasterId,
MasterFIO = MasterFIO,
ServiceId = ServiceId,
ServiceName = ServiceName,
Sum = Sum,
DateOfVisit = DateOfVisit
};
}
}