예제 #1
0
        public static void IsValid(TourPrice tourPrice, int?Id = null)
        {
            Exception ex             = new Exception("Validate excption");
            var       inputDateRange = new DateRange(tourPrice.StartDate, tourPrice.EndDate);
            var       tour           = TourDAL.GetById(tourPrice.TourId);

            if (tour == null)
            {
                ex.Data.Add("Tour", "Không tìm thấy tour");
            }

            var tourPrices = TourPriceDAL.Find(tp => (tp.TourId == tour.Id) && (!Id.HasValue || tp.Id != Id));

            foreach (var x in tourPrices)
            {
                var sourceDateRange = new DateRange(x.StartDate, x.EndDate);
                if (!inputDateRange.BeforeOrAfter(sourceDateRange))
                {
                    ex.Data.Add("Thời gian", "Thời gian bắt đầu và kết thúc không hợp lệ");
                    break;
                }
            }
            if (ex.Data.Count > 0)
            {
                throw ex;
            }
        }