2024-04-29 21:18:01 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-04-28 23:08:12 +04:00
|
|
|
|
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; }
|
|
|
|
|
|
2024-04-29 21:18:01 +04:00
|
|
|
|
[DeleteBehavior(DeleteBehavior.Restrict)]
|
2024-04-28 23:08:12 +04:00
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|