public static void UpdateSeedServiceAreaInfo(this DbAppContext context, ServiceArea serviceAreaInfo) { // Adjust the district. int ministry_district_id = serviceAreaInfo.District.MinistryDistrictID; var exists = context.Districts.Any(a => a.MinistryDistrictID == ministry_district_id); if (exists) { District district = context.Districts.First(a => a.MinistryDistrictID == ministry_district_id); serviceAreaInfo.District = district; } else { serviceAreaInfo.District = null; } ServiceArea serviceArea = context.GetServiceAreaByMinistryServiceAreaId(serviceAreaInfo.MinistryServiceAreaID); if (serviceArea == null) { context.ServiceAreas.Add(serviceAreaInfo); } else { serviceArea.Name = serviceAreaInfo.Name; serviceArea.StartDate = serviceAreaInfo.StartDate; serviceArea.District = serviceAreaInfo.District; } }
/// <summary> /// Adds a service area to the system, only if it does not exist. /// </summary> private static void AddInitialServiceArea(this IDbAppContext context, ServiceArea initialServiceArea) { ServiceArea serviceArea = context.GetServiceAreaByMinistryServiceAreaId(initialServiceArea.MinistryServiceAreaID); if (serviceArea != null) { return; } serviceArea = new ServiceArea(); serviceArea.MinistryServiceAreaID = initialServiceArea.MinistryServiceAreaID; serviceArea.Name = initialServiceArea.Name; serviceArea.StartDate = initialServiceArea.StartDate; if (initialServiceArea.District != null) { District district = context.GetDistrictByMinistryDistrictId(initialServiceArea.District.MinistryDistrictID); serviceArea.District = district; } else { serviceArea.District = null; } context.ServiceAreas.Add(serviceArea); context.SaveChanges(); }
/// <summary> /// Returns a service area for a given Ministry Id /// </summary> /// <param name="context"></param> /// <param name="id">The Ministry Id</param> /// <returns>Region</returns> public static ServiceArea GetServiceAreaByMinistryServiceAreaId(this IDbAppContext context, int id) { ServiceArea serviceArea = context.ServiceAreas.Where(x => x.MinistryServiceAreaID == id) .Include(x => x.District.Region) .FirstOrDefault(); return(serviceArea); }
/// <summary> /// Initializes a new instance of the <see cref="SchoolBusOwner" /> class. /// </summary> /// <param name="Id">Primary Key (required).</param> /// <param name="Name">The name of the School Bus owner as defined by the user/Inspector. Not tied to the ICBC or NSC names, but whatever is most useful for the Inspectors..</param> /// <param name="Status">Status of the School Bus owner - enumerated value Active, Archived.</param> /// <param name="DateCreated">The date-time of the creation of the record from the audit fields. Since this might be surfaced in the API, adding it to the definition..</param> /// <param name="PrimaryContact">Link to the designated Primary Contact for the Inspector to the School Bus Owner organization..</param> /// <param name="ServiceArea">The District to which this School Bus is affliated..</param> /// <param name="NextInspectionDate">The calculated next inspection date from across the School Buses associated with this School Bus Owner.</param> /// <param name="NumberOfBuses">The calculated count of the number of School Buses associated with this School Bus Owner.</param> /// <param name="Contacts">Contacts.</param> public SchoolBusOwner(int Id, string Name = null, string Status = null, DateTime?DateCreated = null, SchoolBusOwnerContact PrimaryContact = null, ServiceArea ServiceArea = null, DateTime?NextInspectionDate = null, int?NumberOfBuses = null, List <SchoolBusOwnerContact> Contacts = null) { this.Id = Id; this.Name = Name; this.Status = Status; this.DateCreated = DateCreated; this.PrimaryContact = PrimaryContact; this.ServiceArea = ServiceArea; this.NextInspectionDate = NextInspectionDate; this.NumberOfBuses = NumberOfBuses; this.Contacts = Contacts; }
/// <summary> /// Initializes a new instance of the <see cref="SchoolBus" /> class. /// </summary> /// <param name="Id">Primary Key (required).</param> /// <param name="Regi">The ICBC Registration number for the School Bus.</param> /// <param name="Plate">The ICBC Plate Number for the School Bus.</param> /// <param name="VIN">The VIN for the School Bus.</param> /// <param name="SchoolBusOwner">SchoolBusOwner.</param> /// <param name="PermitNumber">The (generated) permit number for the School Bus. This will be added by the Inspector before the School Bus Permit can be printed and the bus can go into service..</param> /// <param name="Status">Enumerated type of Status - Inactive, Active, Archived.</param> /// <param name="IsOutOfProvince">IsOutOfProvince.</param> /// <param name="ServiceArea">ServiceArea.</param> /// <param name="HomeTerminalAddr1">Address 1 of physical location of the School Bus..</param> /// <param name="HomeTerminalAddr2">Address 2 of physical location of the School Bus..</param> /// <param name="HomeTerminalCity">City of physical location of the School Bus..</param> /// <param name="HomeTerminalProvince">Province of physical location of the School Bus - free form..</param> /// <param name="HomeTerminalPostalCode">Postal Code of physical location of the School Bus..</param> /// <param name="HomeTerminalComment">A comment about the physical location of the bus so that the Inspector can more easily find it for an inspection.</param> /// <param name="Restrictions">Text of any restrictions to be printed on the school bus permit..</param> /// <param name="NextInspectionDate">The next inspection date for this School Bus. Set at the time an inspection is set..</param> /// <param name="NextInspectionType">An enumerated type (by the UI) to indicate the type of the next inspection - Annual or Re-inspection based on the Pass/Fail status of the most recent inspection..</param> /// <param name="SchoolBusDistrict">The School District in which the School Bus operates. The school bus may or may not be associated with the School District itself - we just track where it is regardless..</param> /// <param name="IsIndependentSchool">True if the School Bus is associated with an Independent School. If true, the name of the Independent School should be in the companion field..</param> /// <param name="NameOfIndependentSchool">The name of the Independent School to which the School Bus is associated. Should be null if the companion isIndependentSchool is false..</param> /// <param name="SchoolBusClass">The enumerated class of School Bus..</param> /// <param name="SchoolBusBodyType">The enumerated body type of the School Bus..</param> /// <param name="SchoolBusBodyTypeOther">The enumerated body type of the School Bus..</param> /// <param name="SchoolBusUnitNumber">The unit number of the Bus as defined by the School Bus owner - freeform text..</param> /// <param name="SchoolBusSeatingCapacity">The maximum number of passengers in the bus based on the specific use of the bus. For example, the same 2-per seat / 24-passenger model might have a seating capacity of 36 if the specific bus is to be used for small children, 3 per seat..</param> /// <param name="MobilityAidCapacity">The number of mobility aid passenger seats in the bus..</param> public SchoolBus(int Id, string Regi = null, string Plate = null, string VIN = null, SchoolBusOwner SchoolBusOwner = null, string PermitNumber = null, string Status = null, bool?IsOutOfProvince = null, ServiceArea ServiceArea = null, string HomeTerminalAddr1 = null, string HomeTerminalAddr2 = null, City HomeTerminalCity = null, string HomeTerminalProvince = null, string HomeTerminalPostalCode = null, string HomeTerminalComment = null, string Restrictions = null, DateTime?NextInspectionDate = null, string NextInspectionType = null, SchoolDistrict SchoolBusDistrict = null, bool?IsIndependentSchool = null, string NameOfIndependentSchool = null, string SchoolBusClass = null, string SchoolBusBodyType = null, string SchoolBusBodyTypeOther = null, string SchoolBusUnitNumber = null, int?SchoolBusSeatingCapacity = null, int?MobilityAidCapacity = null) { this.Id = Id; this.Regi = Regi; this.Plate = Plate; this.VIN = VIN; this.SchoolBusOwner = SchoolBusOwner; this.PermitNumber = PermitNumber; this.Status = Status; this.IsOutOfProvince = IsOutOfProvince; this.ServiceArea = ServiceArea; this.HomeTerminalAddr1 = HomeTerminalAddr1; this.HomeTerminalAddr2 = HomeTerminalAddr2; this.HomeTerminalCity = HomeTerminalCity; this.HomeTerminalProvince = HomeTerminalProvince; this.HomeTerminalPostalCode = HomeTerminalPostalCode; this.HomeTerminalComment = HomeTerminalComment; this.Restrictions = Restrictions; this.NextInspectionDate = NextInspectionDate; this.NextInspectionType = NextInspectionType; this.SchoolBusDistrict = SchoolBusDistrict; this.IsIndependentSchool = IsIndependentSchool; this.NameOfIndependentSchool = NameOfIndependentSchool; this.SchoolBusClass = SchoolBusClass; this.SchoolBusBodyType = SchoolBusBodyType; this.SchoolBusBodyTypeOther = SchoolBusBodyTypeOther; this.SchoolBusUnitNumber = SchoolBusUnitNumber; this.SchoolBusSeatingCapacity = SchoolBusSeatingCapacity; this.MobilityAidCapacity = MobilityAidCapacity; }