/// <summary> /// Creates a new instance of a Building. /// </summary> /// <param name="parcel"></param> /// <param name="id"></param> /// <param name="projectNumber"></param> /// <param name="name"></param> /// <param name="lat"></param> /// <param name="lng"></param> /// <param name="agency"></param> /// <returns></returns> public static Entity.Building CreateBuilding(Entity.Parcel parcel, int id, string projectNumber = null, string name = null, int lat = 0, int lng = 0, Entity.Agency agency = null) { projectNumber ??= $"p{id}"; agency ??= parcel.Agency; var address = EntityHelper.CreateAddress(++parcel.AddressId, parcel.Address.Address1, parcel.Address.Address2, parcel.Address.AdministrativeArea, parcel.Address.Province, parcel.Address.Postal); var predominateUse = EntityHelper.CreateBuildingPredominateUse("use"); var constructionType = EntityHelper.CreateBuildingConstructionType("type"); var occupantType = EntityHelper.CreateBuildingOccupantType("occupant"); var classification = EntityHelper.CreatePropertyClassification("classification"); return(new Entity.Building(parcel, lat, lng) { Id = id, ProjectNumber = projectNumber, AgencyId = agency.Id, Agency = agency, Name = name, 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 } }); }
/// <summary> /// Creates a new instance of a Building. /// </summary> /// <param name="id"></param> /// <param name="projectNumber"></param> /// <param name="name"></param> /// <param name="lat"></param> /// <param name="lng"></param> /// <param name="agency"></param> public static Entity.Building CreateBuilding(int id, string projectNumber = null, string name = null, int lat = 0, int lng = 0, Entity.Agency agency = null) { projectNumber ??= $"p{id}"; agency ??= agency ?? EntityHelper.CreateAgency(id); var address = EntityHelper.CreateAddress(id, "1234 Street", null, "V9C9C9"); var predominateUse = EntityHelper.CreateBuildingPredominateUse("use"); var constructionType = EntityHelper.CreateBuildingConstructionType("type"); var occupantType = EntityHelper.CreateBuildingOccupantType("occupant"); var classification = EntityHelper.CreatePropertyClassification("classification"); return(new Entity.Building() { Id = id, ProjectNumbers = $"[\"{projectNumber}\"]", AgencyId = agency.Id, Agency = agency, Name = name, AddressId = address.Id, Address = address, Location = new Point(lng, lat) { SRID = 4326 }, 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 }, PropertyTypeId = 1, }); }
/// <summary> /// Creates a new instance of a Building. /// </summary> /// <param name="context"></param> /// <param name="parcel"></param> /// <param name="id"></param> /// <param name="localId"></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 localId = null, int lat = 0, int lng = 0, Entity.Agency agency = null) { localId ??= $"l{id}"; agency ??= parcel.Agency; var address = EntityHelper.CreateAddress(id, parcel.Address.Address1, parcel.Address.Address2, parcel.Address.City, 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, ProjectNumber = projectNumber, LocalId = localId, 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 } }; parcel.Buildings.Add(building); context.Buildings.Add(building); return(building); }
/// <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); }