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

62 lines
1.6 KiB
C#
Raw Normal View History

2024-04-28 23:08:12 +04:00
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<TripPlace> Trips { get; set; } = new();
[ForeignKey("PlaceId")]
public virtual List<Excursion> Excursions { get; set; } = new();
2024-04-28 23:08:12 +04:00
public static Place? Create(PlaceBindingModel? model)
{
if (model == null)
{
return null;
}
return new Place()
{
Id = model.Id,
PlaceName = model.PlaceName,
PlaceAddress = model.PlaceAddress
2024-04-28 23:08:12 +04:00
};
}
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
2024-04-28 23:08:12 +04:00
};
}
}