using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; using TravelAgencyContracts.BindingModels; using TravelAgencyContracts.ViewModels; using TravelAgencyDataModels.Models; namespace TravelAgencyDatabaseImplement.Models { public class Place : IPlaceModel { public int Id { get; set; } [Required] public string PlaceName { get; set; } = string.Empty; [Required] public string PlaceAddress { get; set; } = string.Empty; [ForeignKey("PlaceId")] public virtual List Trips { get; set; } = new(); [ForeignKey("PlaceId")] public virtual List Excursions { get; set; } = new(); [ForeignKey("PlaceId")] public virtual List ExcursionGroups { get; set; } = new(); public static Place? Create(PlaceBindingModel? model) { if (model == null) { return null; } return new Place() { Id = model.Id, PlaceName = model.PlaceName, PlaceAddress = model.PlaceAddress }; } public void Update(PlaceBindingModel? model) { if (model == null) { return; } PlaceName = model.PlaceName; PlaceAddress = model.PlaceAddress; } public PlaceViewModel GetViewModel => new() { Id = Id, PlaceName = PlaceName, PlaceAddress = PlaceAddress }; } }