// To add a new country record internal void CreateCountryFormat(CountryFormat country) { try { db.CountryRecord.InsertOne(country); } catch { throw; } }
// Update the records of a particluar country format public void UpdateCountryFormat(CountryFormat countryFormat) { try { db.CountryRecord.ReplaceOne(filter: g => g.Id == countryFormat.Id, replacement: countryFormat); } catch { throw; } }
public ActionResult <CountryFormat> Update([FromBody] CountryFormat countryFormat) { CountryFormat res = _addressService.ReadCountryFormat(countryFormat.Id); if (res == null) { return(NotFound()); } _addressService.UpdateCountryFormat(countryFormat); return(Ok(countryFormat)); }
public ActionResult <CountryFormat> Read(string id) { CountryFormat res = _addressService.ReadCountryFormat(id); if (res != null) { return(Ok(res)); } else { return(NotFound()); } }
public ActionResult <CountryFormat> Delete(string id) { CountryFormat res = _addressService.ReadCountryFormat(id); if (res == null) { return(NotFound()); } _addressService.DeleteCountryFormat(id); return(Ok(res)); }
// validate postal code format public bool PostalCodeValidator(Address address) { try { FilterDefinition <CountryFormat> filterCountry = Builders <CountryFormat> .Filter.Eq(x => x.Name, address.Country); CountryFormat countryFormat = db.CountryRecord.Find(filterCountry).FirstOrDefault(); if (countryFormat == null) { return(true); // if country name is a custom input, then no validation is needed, return true } if (String.IsNullOrEmpty(address.PostalCode)) { if (countryFormat.PostalCodeOptional == true) { return(true); } return(false); } string pattern = countryFormat.PostalCodePattern; if (pattern == null) { return(true); } Match m = Regex.Match(address.PostalCode, pattern); if (m.Success) { return(true); } return(false); } catch { throw; } }
public override void Configure(XmlElement element) { base.Configure(element); Format = XmlUtilities.GetAttribute(element, "format", Format); }
public ActionResult <CountryFormat> Create([FromBody] CountryFormat countryFormat) { _addressService.CreateCountryFormat(countryFormat); return(Ok(countryFormat)); }