Пример #1
0
 // To add a new country record
 internal void CreateCountryFormat(CountryFormat country)
 {
     try
     {
         db.CountryRecord.InsertOne(country);
     }
     catch
     {
         throw;
     }
 }
Пример #2
0
 // 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;
     }
 }
Пример #3
0
        public ActionResult <CountryFormat> Update([FromBody] CountryFormat countryFormat)
        {
            CountryFormat res = _addressService.ReadCountryFormat(countryFormat.Id);

            if (res == null)
            {
                return(NotFound());
            }

            _addressService.UpdateCountryFormat(countryFormat);

            return(Ok(countryFormat));
        }
Пример #4
0
        public ActionResult <CountryFormat> Read(string id)
        {
            CountryFormat res = _addressService.ReadCountryFormat(id);

            if (res != null)
            {
                return(Ok(res));
            }
            else
            {
                return(NotFound());
            }
        }
Пример #5
0
        public ActionResult <CountryFormat> Delete(string id)
        {
            CountryFormat res = _addressService.ReadCountryFormat(id);

            if (res == null)
            {
                return(NotFound());
            }

            _addressService.DeleteCountryFormat(id);

            return(Ok(res));
        }
Пример #6
0
        // 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);
 }
Пример #8
0
 public ActionResult <CountryFormat> Create([FromBody] CountryFormat countryFormat)
 {
     _addressService.CreateCountryFormat(countryFormat);
     return(Ok(countryFormat));
 }
 public override void Configure(XmlElement element)
 {
     base.Configure(element);
     Format = XmlUtilities.GetAttribute(element, "format", Format);
 }