Example #1
0
        /// <summary>
        /// 数据验证
        /// <para>作     者:Huang GaoLiang  </para>
        /// <para>创建时间:2018-11-02 </para>
        /// </summary>
        /// <param name="schoolTime">上课时间段</param>
        /// <returns>返回true/false</returns>
        private static bool DataValidation(SchoolTimeSaveRequest schoolTime)
        {
            // 判断时间是否在周一至周日
            if (schoolTime.WeekDay < (int)Week.Monday || schoolTime.WeekDay > (int)Week.Sunday)
            {
                return(false);
            }

            // 判断时间是否是60分钟还是90分钟
            if (schoolTime.Duration != (int)TimeType.Sixty && schoolTime.Duration != (int)TimeType.Ninety)
            {
                return(false);
            }

            // 判断上课时间和下课时间是否为空
            if (string.IsNullOrWhiteSpace(schoolTime.BeginTime) || string.IsNullOrWhiteSpace(schoolTime.EndTime))
            {
                return(false);
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// 校验数据的合法性
        /// <para>作     者:Huang GaoLiang </para>
        /// <para>创建时间:2018-11-02 </para>
        /// </summary>
        /// <param name="schoolTimeSaveRequestList">上课时间段集合</param>
        /// <param name="schoolTime">上课时间段</param>
        /// <param name="schoolTimeIds">上课时间段编号集合</param>
        /// <exception cref="AMS.Core.BussinessException">
        /// 异常ID:4,您输入的数据有误,请重新输入
        /// 异常ID:5,您输入的时间有误,输入时间段必须为60分钟或者90分钟
        /// 异常ID:6,时间不能交叉
        /// </exception>
        private static void Verification(List <SchoolTimeSaveRequest> schoolTimeSaveRequestList, SchoolTimeSaveRequest schoolTime, List <long> schoolTimeIds)
        {
            // 1数据为空检测
            if (!DataValidation(schoolTime))
            {
                throw new BussinessException((byte)ModelType.Datum, 4);
            }

            // 2、检查时间是不是间隔60分钟和90分钟
            if (!IsRuleTime(schoolTime.BeginTime, schoolTime.EndTime))
            {
                throw new BussinessException((byte)ModelType.Datum, 5);
            }
            // 3、检查集合中有不有交叉的时间段
            if (!CheckDate(schoolTime.BeginTime, schoolTime.Duration, schoolTimeSaveRequestList))
            {
                throw new BussinessException((byte)ModelType.Datum, 6);
            }

            // 4、数据安全性检测
            List <long> requestSchoolTimeIds = schoolTimeSaveRequestList.Where(m => m.SchoolTimeId > 0).Select(m => m.SchoolTimeId).ToList();

            if (!schoolTimeIds.All(m => requestSchoolTimeIds.Any(b => b == m)) || requestSchoolTimeIds.Count != schoolTimeIds.Count)//验证上课时间段主编id与数据库里面的主键id是否匹配
            {
                throw new BussinessException((byte)ModelType.Datum, 4);
            }
        }