public void ValidateUserNameTest8()
        {
            UserBR target = CreateNewUserBR();
            BusinessRuleErrorList errors = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName = RuleFunctionSEnum.Insert;
            bool throwIfErrors           = false;

            List <string> validUserNames = new List <string>();

            //validUserNames.Add("1Mohammad.Ali.Ghaderi"); // starts with number
            validUserNames.Add("Mohammad._Ali_Ghaderi"); // has two characters ._
            validUserNames.Add("Mohammad.Ali_.Ghaderi"); // has two characters _.
            validUserNames.Add("Mohammad1234.");         // ends with .
            validUserNames.Add(".Mohammad1234");         // starts with a symbol
            validUserNames.Add("_Mohammad1234");         // starts with a symbol
            validUserNames.Add("Mohammad!Ali");          // Contains invalid symbol
            validUserNames.Add("Mohammad Ali");          // Contains invalid symbol

            for (int i = 0; i < validUserNames.Count; i++)
            {
                bool isValid = target.ValidateUserName(validUserNames[i], null, errors, fnName, throwIfErrors);
                if (isValid)
                {
                    throw new Exception(validUserNames[i] + " shouldn't be a valid user name.");
                }
            }
        }
Exemple #2
0
        //Please write your properties and functions here. This part will not be replaced.

        public override void CheckRules(object entitySet, RuleFunctionSEnum fnName, BusinessRuleErrorList errors)
        {
            base.CheckRules(entitySet, fnName, errors);
            VitalValue o = (VitalValue)entitySet;

            if (CheckUtils.DateTimeLessThanUtcNow(o.RecordDateTime, vVitalValue.ColumnNames.RecordDateTime, errors))
            {
                CheckUtils.DateTimeIsInUnixRange(o.RecordDateTime, vVitalValue.ColumnNames.RecordDateTime, errors);
            }
        }
        public void CheckRulesTest()
        {
            UserBR                target = CreateNewUserBR();
            User                  user   = CreateNewUserObject();
            RuleFunctionSEnum     fnName = RuleFunctionSEnum.Insert;
            BusinessRuleErrorList errors = new BusinessRuleErrorList();

            target.CheckRules(user, fnName, errors);
            Assert.IsTrue(errors.Count > 5);
        }
Exemple #4
0
        //Please write your properties and functions here. This part will not be replaced.

        public override void CheckRules(object entitySet, RuleFunctionSEnum fnName, BusinessRuleErrorList errors)
        {
            base.CheckRules(entitySet, fnName, errors);

            //Visit visit = (Visit) entitySet;

            if (fnName == RuleFunctionSEnum.Insert)
            {
            }
        }
        public void ValidateEmailTest2()
        {
            UserBR                target  = CreateNewUserBR();
            string                value   = "testemailstringwithoutdomain";
            Nullable <long>       idValue = null;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Insert;
            bool throwIfErrors            = false;
            bool actual   = target.ValidateEmail(value, idValue, errors, fnName, throwIfErrors);
            bool expected = false;

            Assert.AreEqual(expected, actual);
        }
        public void ValidateEmailTest6()
        {
            UserBR                target  = CreateNewUserBR();
            string                value   = "*****@*****.**";
            Nullable <long>       idValue = 2;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Update;
            bool throwIfErrors            = false;
            bool actual   = target.ValidateEmail(value, idValue, errors, fnName, throwIfErrors);
            bool expected = false;

            Assert.AreEqual(expected, actual);
        }
        public void ValidateUserNameTest5()
        {
            UserBR                target  = CreateNewUserBR();
            string                value   = "testExistingUserName";
            Nullable <long>       idValue = 1;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Update;
            bool throwIfErrors            = false;
            bool actual   = target.ValidateUserName(value, idValue, errors, fnName, throwIfErrors);
            bool expected = true;

            Assert.AreEqual(expected, actual);
        }
        public void ValidateUserNameTest9()
        {
            UserBR target = CreateNewUserBR();
            BusinessRuleErrorList errors = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName = RuleFunctionSEnum.Insert;
            bool throwIfErrors           = true;

            for (int i = 0; i < 100; i++)
            {
                string userName = TestUtils.RandomUtils.RandomUserName();
                target.ValidateUserName(userName, null, errors, fnName, throwIfErrors);
            }
        }
        public void ValidateEmailTest4()
        {
            UserBR                target  = CreateNewUserBR();
            string                value   = "ایمیلدرزباندیگر@دامینزباندیگر.کام";
            Nullable <long>       idValue = null;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Insert;
            bool throwIfErrors            = false;
            bool actual   = target.ValidateEmail(value, idValue, errors, fnName, throwIfErrors);
            bool expected = true;

            Assert.AreEqual(expected, actual);
        }
        //Please write your properties and functions here. This part will not be replaced.


        public override void CheckRules(object entitySet, RuleFunctionSEnum fnName, BusinessRuleErrorList errors)
        {
            if (fnName == RuleFunctionSEnum.Update)
            {
                //var foodGroupId = FWUtils.EntityUtils.GetObjectFieldValue(entitySet, vFoodGroup.ColumnNames.FoodGroupID);
                //var groupService = UTD.Tricorder.Common.EntityInfos.FoodGroupItemEN.GetService();
                //var itemsCount = groupService.GetCount(new FilterExpression(vFoodGroupItem.ColumnNames.FoodGroupID, foodGroupId));
                //if (itemsCount == 0)
                //{
                //    errors.Add(new BusinessRuleError(){ ColumnName="", ColumnTitle="", ErrorDescription= BusinessErrorStrings.FoodGroup.NotItemInFoodGroup});
                //}
            }
        }
        public void ValidateUserNameTest2()
        {
            UserBR                target  = CreateNewUserBR();
            string                value   = TestUtils.RandomUtils.RandomUserName();
            Nullable <long>       idValue = null;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Insert;
            bool throwIfErrors            = false;
            bool actual   = target.ValidateUserName(value, idValue, errors, fnName, throwIfErrors);
            bool expected = true;

            Assert.AreEqual(expected, actual);
        }
        public void ValidateUserNameTest3()
        {
            // we want to change a user name of a registered existing id value
            UserBR                target  = CreateNewUserBR();
            string                value   = TestUtils.RandomUtils.RandomUserName();
            Nullable <long>       idValue = 1;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Update;
            bool throwIfErrors            = false;
            bool actual   = target.ValidateUserName(value, idValue, errors, fnName, throwIfErrors);
            bool expected = true;

            Assert.AreEqual(expected, actual);
        }
        //Please write your properties and functions here. This part will not be replaced.

        public override void CheckRules(object entitySet, RuleFunctionSEnum fnName, BusinessRuleErrorList errors)
        {
            base.CheckRules(entitySet, fnName, errors);

            // check to make sure that no duplicate item is exists in the database
            CheckUtils.CheckDuplicateTwoKeyNotToBeExists(entitySet,
                                                         vDoctor_Specialty.ColumnNames.SpecialtyID,
                                                         vDoctor_Specialty.ColumnNames.DoctorID,
                                                         vDoctor_Specialty.ColumnNames.Doctor_SpecialtyID,
                                                         errors,
                                                         null,
                                                         fnName == RuleFunctionSEnum.Insert,
                                                         null);
        }
        public void CheckRulesTest2()
        {
            UserBR target = CreateNewUserBR();

            User user = CreateNewUserObject();

            user.Email    = "*****@*****.**";
            user.UserName = "******";

            RuleFunctionSEnum     fnName = RuleFunctionSEnum.Insert;
            BusinessRuleErrorList errors = new BusinessRuleErrorList();

            target.CheckRules(user, fnName, errors);
            Assert.IsTrue(errors.Count > 3);
        }
Exemple #15
0
        //Please write your properties and functions here. This part will not be replaced.

        public override void CheckRules(object entitySet, RuleFunctionSEnum fnName, BusinessRuleErrorList errors)
        {
            TimeSeriesStrip obj = (TimeSeriesStrip)entitySet;

            if (fnName == RuleFunctionSEnum.Insert)
            {
                obj.EndDateOffset = obj.StartDateOffset;

                CheckUtils.CheckNotEqual(obj.TimeSeriesStripID, Guid.Empty,
                                         vTimeSeriesStrip.ColumnNames.TimeSeriesStripID, errors);

                CheckUtils.CheckNotEqual(obj.TimeSeriesTypeID, 0,
                                         vTimeSeriesStrip.ColumnNames.TimeSeriesTypeID, errors);
            }
        }
Exemple #16
0
        //Please write your properties and functions here. This part will not be replaced.


        public override void CheckRules(object entitySet, RuleFunctionSEnum fnName, BusinessRuleErrorList errors)
        {
            base.CheckRules(entitySet, fnName, errors);

            if (entitySet is Doctor)
            {
                // setting ClinicPhoneSearchable phone
                Doctor obj = (Doctor)entitySet;
                if (fnName != RuleFunctionSEnum.Delete)
                {
                    obj.ClinicPhoneNumberSearchable = UTD.Tricorder.Common.PhoneNumberUtils.MakeSearchablePhoneNumber(obj.ClinicPhoneNumber);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
        public void ValidateUserNameTest7()
        {
            UserBR target = CreateNewUserBR();
            BusinessRuleErrorList errors = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName = RuleFunctionSEnum.Insert;
            bool throwIfErrors           = true;

            List <string> validUserNames = new List <string>();

            validUserNames.Add("Mohammad.Ali.Ghaderi");
            validUserNames.Add("Mohammad_Ali_Ghaderi");
            validUserNames.Add("Mohammad1234");
            validUserNames.Add("Mohammad.Ali.Ghaderi");
            validUserNames.Add("testVerylongUsernameWithoutAnySpecialCharacter1234");

            for (int i = 0; i < validUserNames.Count; i++)
            {
                target.ValidateUserName(validUserNames[i], null, errors, fnName, throwIfErrors);
            }
        }
Exemple #18
0
        //Please write your properties and functions here. This part will not be replaced.

        /// <summary>
        /// Checks the rules.
        /// </summary>
        /// <param name="entitySet">The entity set.</param>
        /// <param name="fnName">Name of the function.</param>
        /// <param name="errors">The errors.</param>
        public override void CheckRules(object entitySet, RuleFunctionSEnum fnName, BusinessRuleErrorList errors)
        {
            this.CheckAutomatedRules(entitySet, fnName, errors);
            if (errors.Count > 0)
            {
                return;
            }

            User obj = (User)entitySet;

            obj.UserName = obj.UserName.ToLower();
            if (string.IsNullOrEmpty(obj.Email) == false)
            {
                obj.Email = obj.Email.ToLower();
            }

            ValidateUserName(obj.UserName, obj.UserID, errors, fnName, false);
            ValidateEmail(obj.Email, obj.UserID, errors, fnName, false);
            ValidatePhoneNumber(obj.PhoneNumber, obj.UserID, true, errors, fnName, false);
        }
        public void ValidateUserNameTest4()
        {
            UserBR                target  = CreateNewUserBR();
            string                value   = "testExistingUserName";
            Nullable <long>       idValue = null;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Update;
            bool throwIfErrors            = false;

            try
            {
                bool actual = target.ValidateUserName(value, idValue, errors, fnName, throwIfErrors);
                Assert.AreNotEqual(actual, true);
            }
            catch (Exception)
            {
                Assert.AreEqual(0, errors.Count);
                // if error happened everything is fine
            }
        }
        //Please write your properties and functions here. This part will not be replaced.

        public override void CheckRules(object entitySet, RuleFunctionSEnum fnName, BusinessRuleErrorList errors)
        {
            base.CheckRules(entitySet, fnName, errors);

            if (CheckUtils.CheckDuplicateTwoKeyNotToBeExists

                    (entitySet
                    , vMedicalHistory.ColumnNames.SectionName,
                    vMedicalHistory.ColumnNames.PatientUserID,
                    vMedicalHistory.ColumnNames.MedicalHistoryID,
                    errors,
                    null,
                    fnName == RuleFunctionSEnum.Insert,
                    null)

                == false)
            {
                // the application shouldn't insert a medical history section when it is exists in the database
                throw new ImpossibleExecutionException("Medical history section is already saved by another user. Please re-save it.");
            }
        }
        public void ValidateUserNameTest6()
        {
            UserBR                target  = CreateNewUserBR();
            string                value   = "testExistingUserName";
            Nullable <long>       idValue = 2;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Update;
            bool throwIfErrors            = true;

            try
            {
                bool actual = target.ValidateUserName(value, idValue, errors, fnName, throwIfErrors);
            }
            catch (BRException ex)
            {
                Assert.AreEqual(BusinessErrorStrings.User.UserName_DuplicateUserName, ex.RuleErrors[0].ErrorDescription);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #22
0
        //Please write your properties and functions here. This part will not be replaced.

        public override void CheckRules(object entitySet, RuleFunctionSEnum fnName, BusinessRuleErrorList errors)
        {
            TimeSeries_SmallInt_Seconds obj = (TimeSeries_SmallInt_Seconds)entitySet;

            if (fnName == RuleFunctionSEnum.Insert)
            {
                //TODO: Check related TimeSeriesStrip exists
                //TODO: Check date is greater than startdate in strip
                //TODO: Check strip is the lastest strip in database

                CheckUtils.CheckNotEqual(obj.TimeSeriesStripID, Guid.Empty,
                                         TimeSeries_SmallInt_Seconds.ColumnNames.TimeSeriesStripID, errors);

                // typeid should be provided
                CheckUtils.CheckNotEqual(obj.TimeSeriesTypeID, 0,
                                         TimeSeries_SmallInt_Seconds.ColumnNames.TimeSeriesTypeID, errors);

                // time should be in unix range
                int maxUtcEpoch = DateTimeEpoch.GetUtcNowEpoch();
                CheckUtils.CheckIntBetweenMinMax(TimeSeries_SmallInt_Seconds.ColumnNames.TSDateOffset, obj.TSDateOffset, errors,
                                                 DateTimeEpoch.UnixMinDateSecondsEpoch, maxUtcEpoch);
            }
        }
Exemple #23
0
        public bool ValidateEmail(string value, long?idValue, BusinessRuleErrorList errors, RuleFunctionSEnum fnName, bool throwIfErrors)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(true);
            }
            //if (CheckUtils.CheckStringShouldNotBeNullOrEmpty(vUser.ColumnNames.Email, value, errors) == false)
            //    if (throwIfErrors)
            //        throw new BRException(errors);
            //    else
            //        return false;


            if (fnName == RuleFunctionSEnum.Delete)
            {
                return(true);
            }

            string colName = vUser.ColumnNames.Email;

            // format check
            // we try to create a mail address. If format was incorrect then its an error
            //http://stackoverflow.com/questions/5342375/c-sharp-regex-email-validation
            try
            {
                System.Net.Mail.MailAddress m = new System.Net.Mail.MailAddress(value);
            }
            catch (Exception)
            {
                errors.Add(colName, BusinessErrorStrings.User.Email_InvalidEmailAddress);
            }

            // check duplicate
            if (errors.Count == 0)       // Perfomance: We check database only if no error is there.
            {
                value = value.ToLower(); // we store all emails in lower case
                CheckUtils.CheckDuplicateValueNotToBeExists(colName, value, idValue, errors, null, fnName == RuleFunctionSEnum.Insert, BusinessErrorStrings.User.Email_Duplicate);
            }

            if (errors.Count > 0 && throwIfErrors)
            {
                throw new BRException(errors);
            }

            return(errors.Count == 0);
        }
Exemple #24
0
        protected virtual void CheckAutomatedRules(object entitySet, RuleFunctionSEnum fnName, BusinessRuleErrorList errors)
        {
            foreach (var colInfo in this.Entity.EntityColumns)
            {
                ColumnInfo col = colInfo.Value;

                if (
                    (col.IsUpdatable && fnName == RuleFunctionSEnum.Update) ||
                    (col.IsInsertable && fnName == RuleFunctionSEnum.Insert)
                    )
                {
                    object val = FWUtils.EntityUtils.GetObjectFieldValue(entitySet, col.Name);

                    // check allow blank for all types
                    if (col.ValidationIsNullable == false)
                    {
                        if (val == null)
                        {
                            errors.Add(col.Name, string.Format(StringMsgs.BusinessErrors.NotNull, col.Caption));
                            continue;
                        }
                        // TODO: fix foreign key integer value checking for int
                        //// for integer values if the column is id column, we check not to enter -1 value (that is the default for not having a value)
                        //if (col.Name.EndsWith("ID") && (val is Int16 || val is Int32 || val is Int64))
                        //    if (Convert.ToInt64(val) == -1)
                        //    {
                        //        errors.Add(col.Name, string.Format(StringMsgs.BusinessErrors.NotNull, col.Caption));
                        //        continue;
                        //    }
                    }

                    // checking string length
                    if (col.DataTypeDotNet == typeof(string))
                    {
                        if (col.ValidationIsNullable == false && ((string)val) == "")
                        {
                            errors.Add(col.Name, string.Format(StringMsgs.BusinessErrors.StringNotNullOrEmpty, col.Caption));
                        }

                        CheckUtils.CheckStringLenBetweenMinAndMax(col.Name, (string)val, errors, col.ValidationMinLength, col.ValidationMaxLength);
                    }

                    // checking minimum maximum value if existed
                    if (col.ValidationMaxValue != null || col.ValidationMinValue != null)
                    {
                        if (col.DataTypeDotNet == typeof(int))
                        {
                            CheckUtils.CheckIntBetweenMinMax(col.Name, (int)val, errors, (int?)col.ValidationMinValue, (int?)col.ValidationMaxValue);
                        }
                        else if (col.DataTypeDotNet == typeof(long))
                        {
                            CheckUtils.CheckLongBetweenMinMax(col.Name, (long)val, errors, (long?)col.ValidationMinValue, (long?)col.ValidationMaxValue);
                        }
                        else if (col.DataTypeDotNet == typeof(double))
                        {
                            CheckUtils.CheckDoubleBetweenMinMax(col.Name, (double)val, errors, (double?)col.ValidationMinValue, (double?)col.ValidationMaxValue);
                        }
                        else if (col.DataTypeDotNet == typeof(float))
                        {
                            CheckUtils.CheckFloatBetweenMinMax(col.Name, (float)val, errors, (float?)col.ValidationMinValue, (float?)col.ValidationMaxValue);
                        }
                        else if (col.DataTypeDotNet == typeof(decimal))
                        {
                            CheckUtils.CheckDecimalBetweenMinMax(col.Name, (decimal)val, errors, (decimal?)col.ValidationMinValue, (decimal?)col.ValidationMaxValue);
                        }
                        else if (col.DataTypeDotNet == typeof(DateTime))
                        {
                            CheckUtils.CheckDateTimeBetweenMinMax(col.Name, (DateTime)val, errors, (DateTime?)col.ValidationMinValue, (DateTime?)col.ValidationMaxValue);
                        }
                        else if (col.DataTypeDotNet == typeof(short))
                        {
                            CheckUtils.CheckShortBetweenMinMax(col.Name, (short)val, errors, (short?)col.ValidationMinValue, (short?)col.ValidationMaxValue);
                        }
                        else if (col.DataTypeDotNet == typeof(byte))
                        {
                            CheckUtils.CheckByteBetweenMinMax(col.Name, (byte)val, errors, (byte?)col.ValidationMinValue, (byte?)col.ValidationMaxValue);
                        }
                    }

                    // duplicate check
                    if (errors.Count == 0 && col.ValidationNoDuplicate) // Perfomance: We check database only if no error is there.
                    {
                        object idValue = ((EntityObjectBase)entitySet).GetPrimaryKeyValue();
                        CheckUtils.CheckDuplicateValueNotToBeExists(col.Name, val, idValue, errors, null, fnName == RuleFunctionSEnum.Insert, null);
                    }
                } // end of if column should be validated or not
            }     // end foreach column
        }
Exemple #25
0
 /// <summary>
 /// Checks the rules.
 /// </summary>
 /// <param name="entitySet">The entity set.</param>
 /// <param name="fnName">Name of the fn.</param>
 /// <param name="errors">The errors.</param>
 /// <exception cref="System.NotImplementedException"></exception>
 public void CheckRulesT(T entitySet, RuleFunctionSEnum fnName, BusinessRuleErrorList errors)
 {
     CheckRules(entitySet, fnName, errors);
 }
Exemple #26
0
        //Please write your properties and functions here. This part will not be replaced.

        public override void CheckRules(object entitySet, RuleFunctionSEnum fnName, BusinessRuleErrorList errors)
        {
            base.CheckRules(entitySet, fnName, errors);

            var obj = (DoctorSchedule)entitySet;

            CheckUtils.CheckByteBetweenMinMax(vDoctorSchedule.ColumnNames.NumberOfAllowedPatients,
                                              obj.NumberOfAllowedPatients, errors, 1, 100);

            CheckUtils.CheckByteBetweenMinMax(vDoctorSchedule.ColumnNames.NumberOfRegisteredPatients,
                                              obj.NumberOfRegisteredPatients, errors, 0, 100);

            if (obj.SlotUnixEpoch <= DateTimeEpoch.GetUtcNowEpoch())
            {
                errors.Add(vDoctorSchedule.ColumnNames.SlotUnixEpoch, BusinessErrorStrings.DoctorSchedule.CannotInsertOldTime);
            }


            if (fnName == RuleFunctionSEnum.Insert)
            {
                DateTime dt = DateTimeEpoch.ConvertSecondsEpochToDateTime(obj.SlotUnixEpoch);

                // removing seconds and milliseconds from Date time (only hour and minute are allowed here)
                // obj.AvailableDateTime = new DateTime(obj.AvailableDateTime.Year, obj.AvailableDateTime.Month, obj.AvailableDateTime.Day, obj.AvailableDateTime.Hour, obj.AvailableDateTime.Minute, 0);
                if (dt.Minute == 0 &&
                    dt.Second == 0 &&
                    dt.Hour == 0
                    )
                {
                    obj.IsWalkingQueue = true;
                }
                else
                {
                    obj.IsWalkingQueue = false;
                }

                // check if time exists

                FilterExpression filter = new FilterExpression();
                filter.AddFilter(new Filter(vDoctorSchedule.ColumnNames.SlotUnixEpoch, obj.SlotUnixEpoch));
                filter.AddFilter(new Filter(vDoctorSchedule.ColumnNames.DoctorID, obj.DoctorID));
                if (DataAccessObject.GetCount(filter) > 0)
                {
                    errors.Add(new BusinessRuleError()
                    {
                        ColumnName       = vDoctorSchedule.ColumnNames.SlotUnixEpoch,
                        ColumnTitle      = this.Entity.EntityColumns[vDoctorSchedule.ColumnNames.SlotUnixEpoch].Caption,
                        ErrorDescription = BusinessErrorStrings.DoctorSchedule.TimeAllocatedBefore
                    });
                }
            }


            // delete rules
            if (fnName == RuleFunctionSEnum.Delete)
            {
                FilterExpression filter = new FilterExpression(vVisit.ColumnNames.DoctorScheduleID, obj.DoctorScheduleID);
                CheckUtils.CheckNoDependantRecordExists(vVisit.EntityName, "", filter, errors, BusinessErrorStrings.DoctorSchedule.CannotDeleteBecauseVisitExists);

                if (obj.SlotUnixEpoch <= DateTimeEpoch.GetUtcNowEpoch())
                {
                    errors.Add(vDoctorSchedule.ColumnNames.SlotUnixEpoch, BusinessErrorStrings.DoctorSchedule.CannotDeleteOldTimeSchedules);
                }
            }
        }
Exemple #27
0
        /// <summary>
        /// Validates the phone number
        /// </summary>
        /// <param name="value">Phone Number</param>
        /// <param name="idValue">id value of the entity. It will be used in update mode to check duplicate</param>
        /// <param name="fnName">Business rule function if it is insert or update</param>
        /// <param name="canBeNull">See if Phone number can be null or empty</param>
        /// <param name="errors">The errors.</param>
        /// <param name="throwIfErrors">Throw BRException if an error happened</param>
        public bool ValidatePhoneNumber(string value, long?idValue, bool canBeNull, BusinessRuleErrorList errors, RuleFunctionSEnum fnName, bool throwIfErrors)
        {
            int errCount = errors.Count;

            // To simplify Signup, we removed Phone number as mandatory
            // in addition, RegisterAndLogin option doesn't need to have a phone number
            // However, if a phone number is provided, we need to check its format
            if (string.IsNullOrEmpty(value) && canBeNull)
            {
                return(true);
            }

            if (CheckUtils.CheckStringShouldNotBeNullOrEmpty(vUser.ColumnNames.PhoneNumber, value, errors) == false)
            {
                if (throwIfErrors && errors.Count > errCount)
                {
                    throw new BRException(errors);
                }
                else
                {
                    return(false);
                }
            }

            string colName = vUser.ColumnNames.PhoneNumber;

            if (fnName == RuleFunctionSEnum.Delete)
            {
                return(true);
            }

            if (IsValidPhoneNumberE164(value) == false)
            {
                errors.Add(colName, BusinessErrorStrings.User.PhoneNumber_NotE164);
            }



            // duplicate check
            if (errors.Count == 0)       // Perfomance: We check database only if no error is there.
            {
                value = value.ToLower(); // we store all user names in lower case
                CheckUtils.CheckDuplicateValueNotToBeExists(colName, value, idValue, errors, null, fnName == RuleFunctionSEnum.Insert, BusinessErrorStrings.User.PhoneNumber_DuplicatePhoneNumber);
            }

            if (errors.Count > 0 && throwIfErrors)
            {
                throw new BRException(errors);
            }

            return(errors.Count == 0);
        }
Exemple #28
0
        /// <summary>
        /// Validates the name of the user.
        /// </summary>
        /// <param name="value">Name of the user.</param>
        /// <param name="idValue">id value of the entity. It will be used in update mode to check duplicate</param>
        /// <param name="fnName">Business rule function if it is insert or update</param>
        /// <param name="errors">The errors.</param>
        /// <param name="throwIfErrors">Throw BRException if an error happened</param>
        public bool ValidateUserName(string value, long?idValue, BusinessRuleErrorList errors, RuleFunctionSEnum fnName, bool throwIfErrors)
        {
            int errCount = errors.Count;

            if (CheckUtils.CheckStringShouldNotBeNullOrEmpty(vUser.ColumnNames.UserName, value, errors) == false)
            {
                if (throwIfErrors && errors.Count > errCount)
                {
                    throw new BRException(errors);
                }
                else
                {
                    return(false);
                }
            }

            string colName = vUser.ColumnNames.UserName;

            //Must consist at least two characters that are alpha characters a-zA-Z
            //Must consist only ONE underscore or dash allowed anywhere AFTER the first check,
            //the dash/underscore cannot be at the end as the same rule to apply as the first step
            //Must be alpha-numeric characters.

            //var colInfo = this.Entity.EntityColumns[User.ColumnNames.UserName];

            if (fnName == RuleFunctionSEnum.Delete)
            {
                return(true);
            }

            // DEVELOPER NOTE: Change this pattern with pattern specified in UI in FWHtml.cs file for editor
            // format check
            // http://stackoverflow.com/questions/3588623/c-sharp-regex-for-a-username-with-a-few-restrictions
            string valuePattern = @"^(?=.{5,50}$)([A-Za-z0-9][._]?)*$";

            //(?=.{5,50}$)                   Must be 5-50 characters in the string
            //([A-Za-z0-9][._()\[\]-]?)*   The string is a sequence of alphanumerics,
            //                              each of which may be followed by a symbol
            if (System.Text.RegularExpressions.Regex.IsMatch(
                    value, valuePattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase) == false)
            {
                errors.Add(colName, BusinessErrorStrings.User.UserName_RegularExpressionCheck
                           );
            }

            // duplicate check
            if (errors.Count == 0)       // Perfomance: We check database only if no error is there.
            {
                value = value.ToLower(); // we store all user names in lower case
                CheckUtils.CheckDuplicateValueNotToBeExists(colName, value, idValue, errors, null, fnName == RuleFunctionSEnum.Insert, BusinessErrorStrings.User.UserName_DuplicateUserName);
            }

            if (errors.Count > 0 && throwIfErrors)
            {
                throw new BRException(errors);
            }

            return(errors.Count == 0);
        }
Exemple #29
0
 /// <summary>
 /// Checks the rules.
 /// </summary>
 /// <param name="entitySet">The entity set.</param>
 /// <param name="fnName">Name of the fn.</param>
 /// <param name="errors">The errors.</param>
 public virtual void CheckRules(object entitySet, RuleFunctionSEnum fnName, BusinessRuleErrorList errors)
 {
     CheckAutomatedRules(entitySet, fnName, errors);
 }