示例#1
0
文件: Building.cs 项目: bcgov/PSP
 /// <summary>
 /// Create a new instance of a Building class.
 /// </summary>
 /// <param name="parcel"></param>
 /// <param name="latitude"></param>
 /// <param name="longitude"></param>
 public Building(Parcel parcel, double latitude, double longitude) : base(latitude, longitude)
 {
     if (parcel != null)
     {
         var pb = new ParcelBuilding(parcel, this);
         this.Parcels.Add(pb);
     }
 }
示例#2
0
        /// <summary>
        /// Creates a new instance of a Building.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="parcel"></param>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="lat"></param>
        /// <param name="lng"></param>
        /// <param name="agency"></param>
        /// <returns></returns>
        public static Entity.Building CreateBuilding(this PimsContext context, Entity.Parcel parcel, int id, string projectNumber = null, string name = null, int lat = 0, int lng = 0, Entity.Agency agency = null)
        {
            name ??= $"l{id}";
            agency ??= parcel?.Agency ?? context.Agencies.FirstOrDefault() ?? EntityHelper.CreateAgency(id);
            var address = (parcel == null ? EntityHelper.CreateAddress(context, id, "1234 Street", null, "V9C9C9") :
                           EntityHelper.CreateAddress(id, parcel.Address.Address1, parcel.Address.Address2, parcel.Address.AdministrativeArea, parcel.Address.Province, parcel.Address.Postal));
            var predominateUse   = context.BuildingPredominateUses.FirstOrDefault(b => b.Id == 1) ?? EntityHelper.CreateBuildingPredominateUse("use");;
            var constructionType = context.BuildingConstructionTypes.FirstOrDefault(b => b.Id == 1) ?? EntityHelper.CreateBuildingConstructionType("type");
            var occupantType     = context.BuildingOccupantTypes.FirstOrDefault(b => b.Id == 1) ?? EntityHelper.CreateBuildingOccupantType("occupant");
            var classification   = context.PropertyClassifications.FirstOrDefault(b => b.Id == 1) ?? EntityHelper.CreatePropertyClassification("classification");

            var building = new Entity.Building(parcel, lat, lng)
            {
                Id                         = id,
                Name                       = name,
                ProjectNumbers             = projectNumber,
                AgencyId                   = agency.Id,
                Agency                     = agency,
                AddressId                  = address.Id,
                Address                    = address,
                Classification             = classification,
                ClassificationId           = classification.Id,
                Description                = $"description-{id}",
                BuildingPredominateUse     = predominateUse,
                BuildingPredominateUseId   = predominateUse.Id,
                BuildingConstructionType   = constructionType,
                BuildingConstructionTypeId = constructionType.Id,
                BuildingOccupantType       = occupantType,
                BuildingOccupantTypeId     = occupantType.Id,
                CreatedById                = Guid.NewGuid(),
                CreatedOn                  = DateTime.UtcNow,
                UpdatedById                = Guid.NewGuid(),
                UpdatedOn                  = DateTime.UtcNow,
                RowVersion                 = new byte[] { 12, 13, 14 }
            };

            if (parcel != null)
            {
                var parcelBuilding = new Entity.ParcelBuilding(parcel, building);
            }
            context.Buildings.Add(building);
            return(building);
        }