Esempio n. 1
0
        /// <summary>
        /// لیست تقویم را برمیگرداند
        /// اگر نوع تقویم رسمی و آیتم های آن در دیتابیس خالی باشد آنگاه تعطیلات تقویم پیشفرض را از دیتابیس بارگزاری میکند
        /// </summary>
        /// <param name="year"></param>
        /// <param name="calendarTypeID"></param>
        /// <param name="CalendarTypeCustomId">اگر رسمی باشد تعطلات سال برگردانده میشود</param>
        /// <returns></returns>
        public IList <CalendarCellInfo> GetCalendarList(int year, decimal calendarTypeID)
        {
            DateTime yearStart, yearEnd;

            if (BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
            {
                string date = String.Format("{0}/01/01", year);
                yearStart = Utility.ToMildiDate(date);
                date      = String.Format("{0}/12/{1}", year, Utility.GetEndOfPersianMonth(year, 12));
                yearEnd   = Utility.ToMildiDate(date);
            }
            else
            {
                yearStart = new DateTime(year, 1, 1);
                yearEnd   = new DateTime(year, 12, Utility.GetEndOfMiladiMonth(year, 12));
            }

            IList <Calendar> calendarList = calendarRepository.GetByCriteria(new CriteriaStruct(Utility.GetPropertyName(() => new Calendar().CalendarType), new CalendarType()
            {
                ID = calendarTypeID
            }),
                                                                             new CriteriaStruct(Utility.GetPropertyName(() => new HolidaysTemplate().Date), yearStart, CriteriaOperation.GreaterEqThan),
                                                                             new CriteriaStruct(Utility.GetPropertyName(() => new HolidaysTemplate().Date), yearEnd, CriteriaOperation.LessEqThan));

            IList <CalendarCellInfo> resultList   = new List <CalendarCellInfo>();
            CalendarType             calendarType = base.GetByID(calendarTypeID);

            if (calendarList.Count == 0 && calendarType.HolidayTemplateList != null)
            {
                ///load default Holidays
                IList <HolidaysTemplate> holidays = calendarType.HolidayTemplateList;

                holidays = holidays.Where(x => x.Date >= yearStart && x.Date <= yearEnd)
                           .ToList <HolidaysTemplate>();

                foreach (HolidaysTemplate holiday in holidays)
                {
                    Calendar cal = new Calendar();
                    cal.CalendarType = new CalendarType()
                    {
                        ID = calendarTypeID
                    };
                    cal.Date = holiday.Date;
                    CalendarCellInfo cell = new CalendarCellInfo(cal);
                    calendarList.Add(cal);
                }
            }
            var result = from calendar in calendarList
                         select new CalendarCellInfo(calendar);

            resultList = result.ToList <CalendarCellInfo>();
            return(resultList);
        }