private string GetStateCode(Country country, string state) { if (state == null | state.Length == 0) return ("--"); // check if country has states defined if (country.States.Count() == 0) return (state); state = state.ToUpper(); // check if state is also the stateCode var thisState = country.States.FirstOrDefault(s => s.StateCode.ToUpper() == state); if (thisState != null) return (thisState.StateCode); // find from English names thisState = country.States.FirstOrDefault(s => s.Name.ToUpper() == state); if (thisState != null) return (thisState.StateCode); // find from Local names thisState = country.States.FirstOrDefault(s => s.LocalName.ToUpper() == state); if (thisState != null) return (thisState.StateCode); return (state); }
/// <summary> /// Return the PPC amount in a given country /// </summary> /// <param name="country">Country to get amount for</param> /// <returns>Amount/Value of PPC in the country</returns> public decimal GetAmount(Country country) { if (country == null) throw new Exception("Invalid country."); return (GetAmount(country.CurrencyCode)); }
/// <summary> /// Get the value of the PPC given a Country. PPC validation is done first. /// </summary> /// <param name="context">DBContext to use</param> /// <param name="serialNumber">Ppc Serial Number</param> /// <param name="pin">Ppc PIN</param> /// <param name="country">Country to get amount for</param> /// <returns>Amount in the currency of Country</returns> static public decimal GetPpcAmount(IPTV2Entities context, string serialNumber, string pin, Country country) { if (country == null) throw new Exception(ErrorCode.InvalidCountry.ToString()); else { return GetPpcAmount(context, serialNumber, pin, country.CurrencyCode); } }
/// <summary> /// Validate a PPC /// </summary> /// <param name="pin">Ppc PIN</param> /// <param name="country">Check if PPC is valid in this Country</param> /// <returns>ErrorCode.Succress if valid, otherwise, see other values</returns> public ErrorCode Validate(string pin, Country country) { if (country == null) return ErrorCode.InvalidCountry; return (Validate(pin, country.CurrencyCode)); }
/// <summary> /// Validate a given serialNumber and pin /// </summary> /// <param name="context">DBContext to be used</param> /// <param name="serialNumber">Ppc Serial Number</param> /// <param name="pin">PPC pin</param> /// <param name="country">Country - check if the PPC is valid for use in this country</param> /// <returns>ErrorCode.Succress if valid, otherwise, see other values</returns> static public ErrorCode Validate(IPTV2Entities context, string serialNumber, string pin, Country country) { if (country == null) return ErrorCode.InvalidCountry; else { return Validate(context, serialNumber, pin, country.CurrencyCode); } }