|
| 1 | +using System.ComponentModel.DataAnnotations; |
| 2 | +using System.ComponentModel.DataAnnotations.Schema; |
| 3 | +using Bing.Domain.Values; |
| 4 | + |
| 5 | +namespace Bing.Biz.Addresses; |
| 6 | + |
| 7 | +/// <summary> |
| 8 | +/// 地址 - 不可变 |
| 9 | +/// </summary> |
| 10 | +public class Address : ValueObjectBase<Address> |
| 11 | +{ |
| 12 | + /// <summary> |
| 13 | + /// 省份编号 |
| 14 | + /// </summary> |
| 15 | + [Column("ProvinceId")] |
| 16 | + public Guid? ProvinceId { get; private set; } |
| 17 | + |
| 18 | + /// <summary> |
| 19 | + /// 城市编号 |
| 20 | + /// </summary> |
| 21 | + [Column("CityId")] |
| 22 | + public Guid? CityId { get; private set; } |
| 23 | + |
| 24 | + /// <summary> |
| 25 | + /// 区县编号 |
| 26 | + /// </summary> |
| 27 | + [Column("CountyId")] |
| 28 | + public Guid? CountyId { get; private set; } |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// 省份 |
| 32 | + /// </summary> |
| 33 | + [Column("Province")] |
| 34 | + [StringLength(100, ErrorMessage = "省份输入过长,不能超过100位")] |
| 35 | + public string Province { get; private set; } |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// 城市 |
| 39 | + /// </summary> |
| 40 | + [Column("City")] |
| 41 | + [StringLength(100, ErrorMessage = "城市输入过长,不能超过100位")] |
| 42 | + public string City { get; private set; } |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// 区县 |
| 46 | + /// </summary> |
| 47 | + [Column("County")] |
| 48 | + [StringLength(100, ErrorMessage = "区县输入过长,不能超过100位")] |
| 49 | + public string County { get; private set; } |
| 50 | + |
| 51 | + /// <summary> |
| 52 | + /// 街道 |
| 53 | + /// </summary> |
| 54 | + [Column("Street")] |
| 55 | + [StringLength(200, ErrorMessage = "街道输入过长,不能超过200位")] |
| 56 | + public string Street { get; private set; } |
| 57 | + |
| 58 | + /// <summary> |
| 59 | + /// 邮政编码 |
| 60 | + /// </summary> |
| 61 | + [Column("Zip")] |
| 62 | + [StringLength(20, ErrorMessage = "邮政编码输入过长,不能超过20位")] |
| 63 | + public string Zip { get; private set; } |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// 地址描述 |
| 67 | + /// </summary> |
| 68 | + public string Description => $"{Province}{City}{County}{Street}"; |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// 空地址 |
| 72 | + /// </summary> |
| 73 | + public static readonly Address Null = new NullAddress(); |
| 74 | + |
| 75 | + /// <summary> |
| 76 | + /// 初始化一个<see cref="Address"/>类型的实例 |
| 77 | + /// </summary> |
| 78 | + public Address() |
| 79 | + { |
| 80 | + } |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// 初始化一个<see cref="Address"/>类型的实例 |
| 84 | + /// </summary> |
| 85 | + /// <param name="provinceId">省份编号</param> |
| 86 | + /// <param name="cityId">城市编号</param> |
| 87 | + /// <param name="countyId">区县编号</param> |
| 88 | + /// <param name="province">省份</param> |
| 89 | + /// <param name="city">城市</param> |
| 90 | + /// <param name="county">区县</param> |
| 91 | + /// <param name="street">街道</param> |
| 92 | + /// <param name="zip">邮政编码</param> |
| 93 | + public Address(Guid? provinceId, Guid? cityId, Guid? countyId, string province, string city, string county, |
| 94 | + string street, string zip = "") |
| 95 | + { |
| 96 | + ProvinceId = provinceId; |
| 97 | + CityId = cityId; |
| 98 | + CountyId = countyId; |
| 99 | + Province = province; |
| 100 | + City = city; |
| 101 | + County = county; |
| 102 | + Street = street; |
| 103 | + Zip = zip; |
| 104 | + } |
| 105 | + |
| 106 | + /// <summary> |
| 107 | + /// 添加描述 |
| 108 | + /// </summary> |
| 109 | + protected override void AddDescriptions() |
| 110 | + { |
| 111 | + AddDescription("省份编号", ProvinceId); |
| 112 | + AddDescription("城市编号", CityId); |
| 113 | + AddDescription("区县编号", CountyId); |
| 114 | + AddDescription("省份", Province); |
| 115 | + AddDescription("城市", City); |
| 116 | + AddDescription("区县", County); |
| 117 | + AddDescription("街道", Street); |
| 118 | + AddDescription("邮政编码", Zip); |
| 119 | + } |
| 120 | +} |
0 commit comments