66 lines
1.4 KiB
C#
66 lines
1.4 KiB
C#
|
using BulletinBoardContracts.BindingModels;
|
|||
|
using BulletinBoardContracts.ViewModels;
|
|||
|
using BulletinBoardDataModels.Models;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel.DataAnnotations;
|
|||
|
using System.ComponentModel.DataAnnotations.Schema;
|
|||
|
using System.Diagnostics;
|
|||
|
using System.Linq;
|
|||
|
using System.Numerics;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace BulletinBoardDatabase.Models
|
|||
|
{
|
|||
|
public class City : ICityModel
|
|||
|
{
|
|||
|
[Required]
|
|||
|
public string CityName { get; set; } = string.Empty;
|
|||
|
|
|||
|
[Required]
|
|||
|
public int? RegionId { get; set; }
|
|||
|
|
|||
|
public int? Id { get; private set; }
|
|||
|
|
|||
|
[ForeignKey("RegionId")]
|
|||
|
List<Announcement> AnnouncementCity { get; set; } = new();
|
|||
|
|
|||
|
public virtual Region Region { get; set; }
|
|||
|
|
|||
|
public static City? Create(CityBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new City()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
CityName = model.CityName,
|
|||
|
RegionId = model.RegionId,
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public void Update(CityBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
CityName = model.CityName;
|
|||
|
RegionId = model.RegionId;
|
|||
|
}
|
|||
|
|
|||
|
public CityViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id,
|
|||
|
CityName = CityName,
|
|||
|
RegionId = RegionId,
|
|||
|
RegionName = Region == null ? string.Empty : Region.RegionName,
|
|||
|
};
|
|||
|
|
|||
|
public string ObjectId => throw new NotImplementedException();
|
|||
|
}
|
|||
|
}
|