SUBD_Labs/BeautySalonDatabaseImplement/Models/Visit.cs

83 lines
2.5 KiB
C#
Raw Normal View History

using BeautySalonContracts.BindingModels;
2023-05-13 16:10:51 +04:00
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; }
[Required]
public int Count { 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,
2023-05-13 16:10:51 +04:00
MasterId = model.MasterId,
MasterFIO = model.MasterFIO,
ServiceId = model.ServiceId,
ServiceName = model.ServiceName,
Count = model.Count,
Sum = model.Sum,
DateOfVisit = model.DateOfVisit
};
}
2023-05-13 16:10:51 +04:00
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;
Count = model.Count;
Sum = model.Sum;
DateOfVisit = model.DateOfVisit;
}
public VisitViewModel GetViewModel => new()
{
Id = Id,
ClientId = ClientId,
ClientFIO = ClientFIO,
MasterId = MasterId,
MasterFIO = MasterFIO,
ServiceId = ServiceId,
ServiceName = ServiceName,
Count = Count,
Sum = Sum,
DateOfVisit = DateOfVisit
};
}
}