/// <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);
        }
示例#2
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);
        }