PIbd-21_Anisin_R.S._CourseW.../TravelAgency/TravelAgencyDatabaseImplement/Models/Tour.cs
2024-04-28 23:08:12 +04:00

74 lines
2.0 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using TravelAgencyContracts.BindingModels;
using TravelAgencyContracts.ViewModels;
using TravelAgencyDataModels.Models;
namespace TravelAgencyDatabaseImplement.Models
{
public class Tour : ITourModel
{
public int Id { get; set; }
[Required]
public string TourName { get; set; } = string.Empty;
public string TourDescription { get; set; } = string.Empty;
[Required]
public double Price { get; set; }
[Required]
public DateTime TourDate { get; set; }
[Required]
public int UserId { get; set; }
public virtual User User { get; set; }
[ForeignKey("TourId")]
public virtual List<ExcursionTour> Excursions { get; set; } = new();
[ForeignKey("TourId")]
public virtual List<ExcursionGroupTour> ExcursionGroups { get; set; } = new();
public static Tour? Create(TourBindingModel? model)
{
if (model == null)
{
return null;
}
return new Tour()
{
Id = model.Id,
TourName = model.TourName,
TourDescription = model.TourDescription,
Price = model.Price,
TourDate = model.TourDate,
UserId = model.UserId,
};
}
public void Update(TourBindingModel? model)
{
if (model == null)
{
return;
}
TourName = model.TourName;
TourDescription = model.TourDescription;
Price = model.Price;
TourDate = model.TourDate;
}
public TourViewModel GetViewModel => new()
{
Id = Id,
TourName = TourName,
TourDescription = TourDescription,
Price = Price,
TourDate = TourDate,
UserId = UserId
};
}
}