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

66 lines
1.7 KiB
C#

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;
[Required]
public int ExcursionId { get; set; }
public virtual Excursion Excursion { get; set; }
[ForeignKey("PlaceId")]
public virtual List<TripPlace> Trips { 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,
ExcursionId = model.ExcursionId
};
}
public void Update(PlaceBindingModel? model)
{
if (model == null)
{
return;
}
PlaceName = model.PlaceName;
PlaceAddress = model.PlaceAddress;
ExcursionId = model.ExcursionId;
}
public PlaceViewModel GetViewModel => new()
{
Id = Id,
PlaceName = PlaceName,
PlaceAddress = PlaceAddress,
ExcursionId = ExcursionId
};
}
}