/// <summary>
        /// Validates NewPatientRequest
        /// </summary>
        /// <param name="exceptionToThrow">exceptionToThrow</param>
        /// <returns></returns>
        public bool ValidateModel(Func <string, Exception> exceptionToThrow = null)
        {
            if (exceptionToThrow == null)
            {
                exceptionToThrow = message => new ArgumentException(message);
            }

            if (Token == null)
            {
                if (Name == null)
                {
                    throw exceptionToThrow("Name is required.");
                }

                if (string.IsNullOrEmpty(Name.First))
                {
                    // error: first name required.
                    throw exceptionToThrow("First name required.");
                }

                if (string.IsNullOrEmpty(Email))
                {
                    // error: email required.
                    throw exceptionToThrow("Email address required.");
                }

                if (string.IsNullOrWhiteSpace(Address) && AddressObject.SafeIsEmpty())
                {
                    // error: address required.
                    throw exceptionToThrow("Address required.");
                }
            }
            if (Dob == null)
            {
                // error: date of birth required.
                throw exceptionToThrow("Date of birth required.");
            }


            if (ProviderId <= 0)
            {
                // error: mobile number required.
                throw exceptionToThrow("ProviderId required.");
            }

            if (!string.IsNullOrEmpty(MobileNumberWithCountryCode) && !MobileNumberWithCountryCode.StartsWith("+"))
            {
                throw exceptionToThrow("Country code is required while entering MobilePhone");
            }

            if (!string.IsNullOrEmpty(Gender) && !(Gender.ToUpper() == "M" || Gender.ToUpper() == "F"))
            {
                throw exceptionToThrow($"Invalid entry for gender {Gender}");
            }
            return(true);
        }
        private bool Equals(AddressObject other)
        {
#pragma warning disable S1067 // Expressions should not be too complex
            return(string.Equals(Line1, other.Line1, StringComparison.OrdinalIgnoreCase) &&
                   string.Equals(Line2, other.Line2, StringComparison.OrdinalIgnoreCase) &&
                   string.Equals(City, other.City, StringComparison.OrdinalIgnoreCase) &&
                   string.Equals(State, other.State, StringComparison.OrdinalIgnoreCase) &&
                   string.Equals(StateCode, other.StateCode, StringComparison.OrdinalIgnoreCase) &&
                   string.Equals(PostalCode, other.PostalCode, StringComparison.OrdinalIgnoreCase) &&
                   string.Equals(Country, other.Country, StringComparison.OrdinalIgnoreCase) &&
                   string.Equals(CountryCode, other.CountryCode, StringComparison.OrdinalIgnoreCase));

#pragma warning restore S1067 // Expressions should not be too complex
        }
Esempio n. 3
0
        /// <summary>
        /// Validate model
        /// </summary>
        /// <param name="exceptionToThrow">exceptionToThrow</param>
        /// <param name="allowNullEmail">allowNullEmail</param>
        /// <returns></returns>
        public bool ValidateModel(Func <string, Exception> exceptionToThrow = null, bool allowNullEmail = false)
        {
            if (exceptionToThrow == null)
            {
                exceptionToThrow = message => new ArgumentException(message);
            }

            if (string.IsNullOrEmpty(FirstName))
            {
                // error: first name required.
                throw exceptionToThrow("First name required.");
            }

            if (!allowNullEmail && string.IsNullOrWhiteSpace(Email))
            {
                // error: email required.
                throw exceptionToThrow("Email address required.");
            }

            var genders = new List <string> {
                "M", "F"
            };

            if (string.IsNullOrEmpty(Gender) || !genders.Contains(Gender))
            {
                // error: gender unknown.
                throw exceptionToThrow(string.Format("Unknown gender. Expected gender any [{0}]", string.Join(", ", genders.ToArray())));
            }

            if (Dob == null)
            {
                // error: date of birth required.
                throw exceptionToThrow("Date of birth required.");
            }
            if (string.IsNullOrEmpty(Address) && AddressObject.SafeIsEmpty())
            {
                // error: address required.
                throw exceptionToThrow("Address required.");
            }

            if (string.IsNullOrEmpty(MobileNumberWithCountryCode))
            {
                // error: mobile number required.
                throw exceptionToThrow("Mobile number required.");
            }

            return(true);
        }