PIbd-21_Anisin_R.S._CourseW.../TravelAgency/TravelAgencyDatabaseImplement/Models/Guide.cs

62 lines
1.6 KiB
C#
Raw Permalink Normal View History

2024-04-28 23:08:12 +04:00
using System.ComponentModel.DataAnnotations;
2024-04-29 21:56:45 +04:00
using System.ComponentModel.DataAnnotations.Schema;
2024-04-28 23:08:12 +04:00
using TravelAgencyContracts.BindingModels;
using TravelAgencyContracts.ViewModels;
using TravelAgencyDataModels.Models;
namespace TravelAgencyDatabaseImplement.Models
{
public class Guide : IGuideModel
{
public int Id { get; set; }
[Required]
public string GuideFIO { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public string PhoneNumber { get; set; } = string.Empty;
2024-04-29 21:56:45 +04:00
[ForeignKey("GuideId")]
public virtual List<Trip> Trips { get; set; } = new();
[ForeignKey("GuideId")]
public virtual List<ExcursionGroup> ExcursionGroups { get; set; } = new();
2024-04-28 23:08:12 +04:00
public static Guide? Create(GuideBindingModel? model)
{
if (model == null)
{
return null;
}
return new Guide()
{
Id = model.Id,
GuideFIO = model.GuideFIO,
Email = model.Email,
PhoneNumber = model.PhoneNumber
};
}
public void Update(GuideBindingModel? model)
{
if (model == null)
{
return;
}
GuideFIO = model.GuideFIO;
Email = model.Email;
PhoneNumber = model.PhoneNumber;
}
public GuideViewModel GetViewModel => new()
{
Id = Id,
GuideFIO = GuideFIO,
Email = Email,
PhoneNumber = PhoneNumber
};
}
}