//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); } } }
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 }