public static int GetAddressId(StudioDbContext context, int?cityId) { var inputAddressData = new InputAddressData { Street = GConst.ValidName, Number = GConst.ValidAddressNumber }; Address address = new Address { AddressFormat = AddressFormat.For(inputAddressData) }; if (cityId != null) { address = new Address { AddressFormat = AddressFormat.For(inputAddressData), CityId = cityId.Value }; } context.Addresses.Add(address); context.SaveChangesAsync(); var addressId = context.Addresses.SingleOrDefault(x => x.AddressFormat.Street == GConst.ValidName).Id; return(addressId); }
//creates header for facility address and adds to dictionary protected static void addFacilityAddress(Dictionary <string, string> header, Facility.FacilityBasic basic) { if (basic != null) { header.Add(Resources.GetGlobal("Facility", "FacilityAddress"), AddressFormat.Format(basic.Address, basic.City, basic.PostalCode, basic.Confidential)); } }
public static AddressFormat CreateAddressFormat(string addressFormat1) { AddressFormat addressFormat = new AddressFormat(); addressFormat.AddressFormat1 = addressFormat1; return(addressFormat); }
public void ToStringReturnsCorrectFormat() { string address = AddressFormat.For(addressData); string result = address.ToString(); Assert.Equal(Value, result); }
public void ImplicitConversionToStringResultsInCorrectString() { var address = AddressFormat.For(addressData); string result = address; Assert.Equal(Value, result); }
internal override string FormatAddress(Participant participant, AddressFormat addressFormat) { if (addressFormat == AddressFormat.Rfc822Smtp) { return(string.Format("\"{0}\" <{1}>", participant.DisplayName, participant.EmailAddress)); } return(base.FormatAddress(participant, addressFormat)); }
internal virtual string FormatAddress(Participant participant, AddressFormat addressFormat) { if (addressFormat == AddressFormat.OutlookFormat) { return(string.Format("\"{0}\" [{2}:{1}]", participant.DisplayName, participant.EmailAddress, participant.RoutingType)); } return(null); }
internal override string FormatAddress(Participant participant, AddressFormat addressFormat) { if (addressFormat == AddressFormat.OutlookFormat || addressFormat == AddressFormat.Rfc822Smtp) { return(participant.DisplayName); } return(base.FormatAddress(participant, addressFormat)); }
public void ShouldHaveCorrectStreetNumberBuildingAndEntrance() { var address = AddressFormat.For(addressData); Assert.Equal(Street, address.Street); Assert.Equal(Number, address.Number); Assert.Equal(Building, address.Building); Assert.Equal(Entrance, address.Entrance); Assert.Null(address.Floor); Assert.Null(address.Apartment); Assert.Null(address.District); }
private static string GetContactPointInfo(ExternalPractitionerContactPointDetail cp) { var builder = new StringBuilder(); builder.AppendFormat("Description: {0}", cp.Description); builder.AppendLine(); builder.AppendFormat(SR.FormatPhone, cp.CurrentPhoneNumber == null ? "" : TelephoneFormat.Format(cp.CurrentPhoneNumber)); builder.AppendLine(); builder.AppendFormat(SR.FormatFax, cp.CurrentFaxNumber == null ? "" : TelephoneFormat.Format(cp.CurrentFaxNumber)); builder.AppendLine(); builder.AppendFormat(SR.FormatAddress, cp.CurrentAddress == null ? "" : AddressFormat.Format(cp.CurrentAddress)); builder.AppendLine(); builder.AppendFormat(SR.FormatEmail, cp.CurrentEmailAddress == null ? "" : cp.CurrentEmailAddress.Address); return(builder.ToString()); }
/// <summary> /// Updates name/address pair. /// </summary> /// <param name="localGeocoderRecord">Local geocoder record.</param> /// <param name="format">Current Address Format.</param> public void InsertOrUpdate(NameAddressRecord localGeocoderRecord, AddressFormat format) { Debug.Assert(localGeocoderRecord != null); Debug.Assert(_IsInitialized()); try { NameAddressRecord recordFromDB = _GetRecordFromDB( localGeocoderRecord.NameAddress, format); string queryStr = string.Empty; if (recordFromDB != null) { // Need to update record. // Choose queries in dependence of used address format. if (format == AddressFormat.SingleField) { queryStr = FULL_ADDRESS_UPDATE_QUERY; } else if (format == AddressFormat.MultipleFields) { queryStr = UPDATE_QUERY; } else { // Do nothing. } } else { // Need to insert record. queryStr = INSERT_QUERY; } SqlCeCommand command = new SqlCeCommand(queryStr, _connection); _FillRecordCommandParameters(localGeocoderRecord, command); int count = command.ExecuteNonQuery(); Debug.Assert(count == 1); } catch (Exception ex) { // Exception can be thrown if some other instance of the // application added the item before this one. Logger.Warning(ex); } }
/// <summary> /// Get record from database. /// </summary> /// <param name="nameAddress">Name\address pair to find.</param> /// <param name="format">Current Address Format.</param> /// <returns>Extracted record.</returns> private NameAddressRecord _GetRecordFromDB(NameAddress nameAddress, AddressFormat format) { NameAddressRecord nameAddressRecord = null; string queryStr = string.Empty; // Choose queries in dependence of used address format. if (format == AddressFormat.SingleField) { queryStr = FULL_ADDRESS_SELECT_QUERY; } else if (format == AddressFormat.MultipleFields) { queryStr = SELECT_QUERY; } else { // Do nothing. } SqlCeCommand command = new SqlCeCommand(queryStr, _connection); _FillCommandParameters(nameAddress, command); SqlCeDataReader reader = null; try { reader = command.ExecuteReader(); if (reader.Read()) { nameAddressRecord = _ReadRecord(reader); } } finally { if (reader != null) { reader.Close(); } } return(nameAddressRecord); }
/// <summary> /// Searches in local storage by name/address pair. /// </summary> /// <param name="nameAddress">Name/address pair to search.</param> /// <param name="format">Current Address Format.</param> /// <returns>Name address record.</returns> public NameAddressRecord Search(NameAddress nameAddress, AddressFormat format) { Debug.Assert(nameAddress != null); Debug.Assert(_IsInitialized()); NameAddressRecord recordFromDB = null; try { recordFromDB = _GetRecordFromDB(nameAddress, format); } catch (Exception ex) { Logger.Warning(ex); } return(recordFromDB); }
public static string ToFormat(this IAddress from, AddressFormat format, bool showPostcode = true, bool showCountry = false) { string ret = ""; if (from == null || !from.Address1.IsSet()) { return(ret); } switch (format) { case AddressFormat.Short: ret = from.Address1; ret += from.City.IsSet() ? ", " + from.City : ""; ret += from.Postcode.IsSet() ? ", " + from.Postcode : ""; break; case AddressFormat.SingleLine: ret = ""; ret += from.Number.IsSet() ? from.Number + (from.Address1.IsSet() ? ", " : "") : ""; ret += from.Address1.IsSet() ? from.Address1 : ""; ret += from.Address2.IsSet() ? ", " + from.Address2 : ""; ret += from.City.IsSet() ? ", " + from.City : ""; ret += from.County.IsSet() ? ", " + from.County : ""; ret += from.Postcode.IsSet() && showPostcode ? ", " + from.Postcode : ""; ret += from.Country.IsSet() && showCountry ? ", " + from.Country : ""; return(ret); case AddressFormat.MultiLine: ret = ""; ret += from.Number.IsSet() ? from.Number + (from.Address1.IsSet() ? ", " : "") : ""; ret += from.Address1.IsSet() ? from.Address1 : ""; ret += from.Address2.IsSet() ? Environment.NewLine + from.Address2 : ""; ret += from.City.IsSet() ? Environment.NewLine + from.City : ""; ret += from.County.IsSet() ? Environment.NewLine + from.County : ""; ret += from.Postcode.IsSet() && showPostcode ? Environment.NewLine + from.Postcode : ""; ret += from.Country.IsSet() && showCountry ? Environment.NewLine + from.Country : ""; return(ret); } return(ret); }
public async Task <Unit> Handle(UpdateAddressCommand request, CancellationToken cancellationToken) { var address = await this.context.Addresses .SingleOrDefaultAsync(a => a.Id == request.Id && a.IsDeleted != true, cancellationToken); if (address == null) { throw new NotFoundException(GConst.Address, request.Id); } var city = await this.context.Cities.FindAsync(request.CityId); if (city == null || city.IsDeleted == true) { throw new UpdateFailureException(GConst.Address, request.Street, string.Format(GConst.RefereceException, GConst.CityLower, request.CityId)); } var inputAddressData = new InputAddressData { Street = request.Street, Number = request.Number, Building = request.Building, Entrance = request.Entrance, Floor = request.Floor, Apartment = request.Apartment, District = request.District }; address.AddressFormat = AddressFormat.For(inputAddressData); address.Longitude = request.Longitude; address.Latitude = request.Latitude; address.CityId = request.CityId; address.ModifiedOn = DateTime.UtcNow; this.context.Addresses.Update(address); await this.context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(CreateAddressCommand request, CancellationToken cancellationToken) { var city = await this.context.Cities.FindAsync(request.CityId); if (city == null || city.IsDeleted == true) { throw new CreateFailureException(GConst.Address, request.Street, string.Format(GConst.RefereceException, GConst.CityLower, request.CityId)); } var inputAddressData = new InputAddressData { Street = request.Street, Number = request.Number, Building = request.Building, Entrance = request.Entrance, Floor = request.Floor, Apartment = request.Apartment, District = request.District }; var address = new Address { AddressFormat = AddressFormat.For(inputAddressData), Latitude = request.Latitude, Longitude = request.Longitude, CityId = request.CityId, CreatedOn = DateTime.UtcNow, IsDeleted = false }; this.context.Addresses.Add(address); await this.context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
/// <summary> /// Formats the specified address (must be a JSML encoded <see cref="AddressDetail"/> object). /// </summary> /// <param name="jsml"></param> /// <returns></returns> public string FormatAddress(string jsml) { var addressDetail = JsmlSerializer.Deserialize <AddressDetail>(jsml); return(addressDetail == null ? "" : AddressFormat.Format(addressDetail)); }
public ExternalPractitionerContactPointTable() : base(NumRows) { var activeColumn = new TableColumn <ExternalPractitionerContactPointDetail, bool>(SR.ColumnActive, cp => !cp.Deactivated, SetDeactivatedStatus, 0.1f); var defaultColumn = new TableColumn <ExternalPractitionerContactPointDetail, bool>(SR.ColumnDefault, cp => cp.IsDefaultContactPoint, MakeDefaultContactPoint, 0.1f); var nameColumn = new TableColumn <ExternalPractitionerContactPointDetail, string>(SR.ColumnName, cp => cp.Name, 0.3f); var descriptionColumn = new TableColumn <ExternalPractitionerContactPointDetail, string>(SR.ColumnDescription, cp => cp.Description, 0.5f); var phoneColumn = new TableColumn <ExternalPractitionerContactPointDetail, string>(SR.ColumnPhone, cp => string.Format(SR.FormatPhone, cp.CurrentPhoneNumber == null ? "" : TelephoneFormat.Format(cp.CurrentPhoneNumber)), 1.0f, PhoneRow); var faxColumn = new TableColumn <ExternalPractitionerContactPointDetail, string>(SR.ColumnFax, cp => string.Format(SR.FormatFax, cp.CurrentFaxNumber == null ? "" : TelephoneFormat.Format(cp.CurrentFaxNumber)), 1.0f, FaxRow); var addressColumn = new TableColumn <ExternalPractitionerContactPointDetail, string>(SR.ColumnAddress, cp => string.Format(SR.FormatAddress, cp.CurrentAddress == null ? "" : AddressFormat.Format(cp.CurrentAddress)), 1.0f, AddressRow); var emailColumn = new TableColumn <ExternalPractitionerContactPointDetail, string>(SR.ColumnEmail, cp => string.Format(SR.FormatEmail, cp.CurrentEmailAddress == null ? "" : cp.CurrentEmailAddress.Address), 1.0f, EmailRow); this.Columns.Add(activeColumn); this.Columns.Add(defaultColumn); this.Columns.Add(nameColumn); this.Columns.Add(descriptionColumn); this.Columns.Add(phoneColumn); this.Columns.Add(faxColumn); this.Columns.Add(addressColumn); this.Columns.Add(emailColumn); }
public AddressTable() { this.Columns.Add(new TableColumn <AddressDetail, string>(SR.ColumnType, delegate(AddressDetail a) { return(a.Type.Value); }, 1.1f)); this.Columns.Add(new TableColumn <AddressDetail, string>(SR.ColumnAddress, delegate(AddressDetail a) { return(AddressFormat.Format(a)); }, 2.2f)); this.Columns.Add(new DateTableColumn <AddressDetail>(SR.ColumnExpiryDate, delegate(AddressDetail a) { return(a.ValidRangeUntil); }, 0.9f)); }
//protected string GetTreaterCountryCode(object obj) //{ // return ((QueryLayer.WasteTransfers.ResultHazardousWasteTreater)obj).TreaterCountryCode; //} protected string GetTreaterSiteAddress(object obj) { WasteTransfers.ResultHazardousWasteTreater row = (WasteTransfers.ResultHazardousWasteTreater)obj; return(AddressFormat.Format(row.TreaterSiteAddress, row.TreaterSiteCity, row.TreaterSitePostalCode, row.TreaterSiteCountryCode, row.ConfidentialIndicator)); }
/// <summary> /// Manual insertion of all facility level details into List, which is in turn bound to GridView /// </summary> private void populateDetails(int facilityReportId) { FACILITYDETAIL_DETAIL fac = Facility.GetFacilityDetails(facilityReportId).First(); FACILITYDETAIL_COMPETENTAUTHORITYPARTY authority = Facility.GetFacilityCompetentAuthority(facilityReportId).First(); List <FacilityDetailElement> elements = new List <FacilityDetailElement>(); elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "FacilityDetailsTitle"), String.Empty, true)); elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "ParentCompanyName"), ConfidentialFormat.Format(fac.ParentCompanyName, fac.ConfidentialIndicator))); // Take "Valid" string from FACILITY_DETAIL_DETAIL elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "Coords"), CoordinateFormat.Format(fac.Coordinates, "VALID"))); //NUTS is voluntary. Only add if reported. if (!string.IsNullOrEmpty(fac.NUTSRegionSourceCode)) { //Add both reported and geo-coded value - if they differ. if (fac.NUTSRegionSourceCode != fac.NUTSRegionLevel2Code) { elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "NUTSMap"), LOVResources.NutsRegionName(fac.NUTSRegionLevel2Code))); elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "NUTSReported"), LOVResources.NutsRegionName(fac.NUTSRegionSourceCode))); } else { elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "NUTS"), LOVResources.NutsRegionName(fac.NUTSRegionLevel2Code))); } } //Add both reported and geo-coded value - if they differ. if (fac.RiverBasinDistrictSourceCode != fac.RiverBasinDistrictCode) { elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "RBDMap"), LOVResources.RiverBasinDistrictName(fac.RiverBasinDistrictCode))); elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "RBDReported"), LOVResources.RiverBasinDistrictName(fac.RiverBasinDistrictSourceCode))); } else { elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "RBD"), LOVResources.RiverBasinDistrictName(fac.RiverBasinDistrictCode))); } //NACE code reported on sub-activity level, except for EPER where some is reported on Activity level //string naceCode = !String.IsNullOrEmpty(fac.NACESubActivityCode) ? fac.NACESubActivityCode : fac.NACEActivityCode; string naceCode = !String.IsNullOrEmpty(fac.NACEActivityCode) ? fac.NACEActivityCode : fac.NACESectorCode; elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "NACE"), LOVResources.NaceActivityName(naceCode))); //Production volume is voluntary. Only add if reported. if (fac.ProductionVolumeQuantity != null) { elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "ProductionV"), String.Format("{0} {1} {2}", fac.ProductionVolumeProductName, NumberFormat.Format(fac.ProductionVolumeQuantity), LOVResources.UnitName(fac.ProductionVolumeUnitCode)))); } //No. of IPPC installations is voluntary. Only add if reported. if (fac.TotalIPPCInstallationQuantity != null) { elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "IPPC"), NumberFormat.Format(fac.TotalIPPCInstallationQuantity))); } //No. of emplyees is voluntary. Only add if reported. if (fac.TotalEmployeeQuantity != null) { elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "Employ"), NumberFormat.Format(fac.TotalEmployeeQuantity))); } //Operating hours is voluntary. Only add if reported. if (fac.OperatingHours != null) { elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "OperationHours"), String.Format("{0}", fac.OperatingHours))); } //Website is voluntary. Only add if reported. if (!string.IsNullOrEmpty(fac.WebsiteCommunication)) { elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "WebSite"), String.Format("{0}", fac.WebsiteCommunication))); } if (fac.ConfidentialIndicatorCode != null) { elements.Add(new FacilityDetailElement( Resources.GetGlobal("Pollutant", "ConfidentialityReason"), LOVResources.ConfidentialityReason(fac.ConfidentialIndicatorCode))); } elements.Add(new FacilityDetailElement( Resources.GetGlobal("Common", "NationalID") + ":", FacilityDetailsFormat.FormatNationalId(fac))); // This is not the most elegant way to obtain a spacing spacing elements.Add(new FacilityDetailElement(String.Empty, String.Empty)); string updatedDateString = authority.CALastUpdate == null ? Resources.GetGlobal("Facility", "LastUpdatedUnknown") : authority.CALastUpdate.Format(); elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "CompetentA"), String.Format(Resources.GetGlobal("Facility", "LastUpdated"), updatedDateString), true)); elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "Name"), String.Format(authority.CAName))); if (authority.CAAddress != null) { elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "Address"), AddressFormat.Format(authority.CAAddress, authority.CACity, authority.CAPostalCode, false))); } if (authority.CATelephoneCommunication != null) { elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "Phone"), String.Format(authority.CATelephoneCommunication))); } if (authority.CAFaxCommunication != null) { elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "Fax"), String.Format(authority.CAFaxCommunication))); } elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "Email"), String.Format(authority.CAEmailCommunication))); if (authority.CAContactPersonName != null) { elements.Add(new FacilityDetailElement( Resources.GetGlobal("Facility", "CPerson"), String.Format(authority.CAContactPersonName))); } // data binding facilityreportDetails.DataSource = elements; facilityreportDetails.DataBind(); }
protected string GetWHPSiteAddress(object obj) { FACILITYDETAIL_WASTETRANSFER row = (FACILITYDETAIL_WASTETRANSFER)obj; return(AddressFormat.Format(row.WHPSiteAddress, row.WHPSiteCity, row.WHPSitePostalCode, row.ConfidentialIndicator)); }
public static IHtmlContent FormatAddress(this IHtmlHelper html, IAddress address, AddressFormat format, bool showPostcode = true, bool showCountry = false) { string ret = ""; if (address == null || !address.Address1.IsSet()) { return(html.Raw(ret)); } switch (format) { case AddressFormat.Short: ret = address.Address1; ret += address.City.IsSet() ? ", " + address.City : ""; ret += address.Postcode.IsSet() ? ", " + address.Postcode : ""; break; case AddressFormat.SingleLine: ret = address.Address1; ret += address.Address2.IsSet() ? ", " + address.Address2 : ""; ret += address.City.IsSet() ? ", " + address.City : ""; ret += address.County.IsSet() ? ", " + address.County : ""; ret += address.Postcode.IsSet() && showPostcode ? ", " + address.Postcode : ""; ret += address.Country.IsSet() && showCountry ? ", " + address.Country : ""; break; case AddressFormat.MultiLine: ret = address.Address1; ret += address.Address2.IsSet() ? "<br />" + address.Address2 : ""; ret += address.City.IsSet() ? "<br />" + address.City : ""; ret += address.County.IsSet() ? "<br />" + address.County : ""; ret += address.Postcode.IsSet() && showPostcode ? "<br />" + address.Postcode : ""; ret += address.Country.IsSet() && showCountry ? "<br />" + address.Country : ""; break; } return(html.Raw(ret)); }
/// <summary> /// Updates name/address pair. /// </summary> /// <param name="localGeocoderRecord">Local geocoder record.</param> /// <param name="format">Current Address Format.</param> public void InsertOrUpdate(NameAddressRecord localGeocoderRecord, AddressFormat format) { Debug.Assert(localGeocoderRecord != null); Debug.Assert(_IsInitialized()); try { NameAddressRecord recordFromDB = _GetRecordFromDB( localGeocoderRecord.NameAddress, format); string queryStr = string.Empty; if (recordFromDB != null) { // Need to update record. // Choose queries in dependence of used address format. if (format == AddressFormat.SingleField) queryStr = FULL_ADDRESS_UPDATE_QUERY; else if (format == AddressFormat.MultipleFields) queryStr = UPDATE_QUERY; else { // Do nothing. } } else { // Need to insert record. queryStr = INSERT_QUERY; } SqlCeCommand command = new SqlCeCommand(queryStr, _connection); _FillRecordCommandParameters(localGeocoderRecord, command); int count = command.ExecuteNonQuery(); Debug.Assert(count == 1); } catch (Exception ex) { // Exception can be thrown if some other instance of the // application added the item before this one. Logger.Warning(ex); } }
/// <summary> /// Searches in local storage by name/address pair. /// </summary> /// <param name="nameAddress">Name/address pair to search.</param> /// <param name="format">Current Address Format.</param> /// <returns>Name address record.</returns> public NameAddressRecord Search(NameAddress nameAddress, AddressFormat format) { Debug.Assert(nameAddress != null); Debug.Assert(_IsInitialized()); NameAddressRecord recordFromDB = null; try { recordFromDB = _GetRecordFromDB(nameAddress, format); } catch (Exception ex) { Logger.Warning(ex); } return recordFromDB; }
/// <summary> /// Get record from database. /// </summary> /// <param name="nameAddress">Name\address pair to find.</param> /// <param name="format">Current Address Format.</param> /// <returns>Extracted record.</returns> private NameAddressRecord _GetRecordFromDB(NameAddress nameAddress, AddressFormat format) { NameAddressRecord nameAddressRecord = null; string queryStr = string.Empty; // Choose queries in dependence of used address format. if (format == AddressFormat.SingleField) queryStr = FULL_ADDRESS_SELECT_QUERY; else if (format == AddressFormat.MultipleFields) queryStr = SELECT_QUERY; else { // Do nothing. } SqlCeCommand command = new SqlCeCommand(queryStr, _connection); _FillCommandParameters(nameAddress, command); SqlCeDataReader reader = null; try { reader = command.ExecuteReader(); if (reader.Read()) { nameAddressRecord = _ReadRecord(reader); } } finally { if (reader != null) { reader.Close(); } } return nameAddressRecord; }