Пример #1
0
        public static int GetPeriodId(this DateTime period)
        {
            var         periods     = GetPeriods();
            PeriodModel periodModel = periods.FirstOrDefault(x => x.Month == period.Month && x.Year == period.Year);

            if (periodModel == null)
            {
                throw new ArgumentException("Не удается найти период для даты {0}", period.ToString("dd.MM.yyyy"));
            }

            return(periodModel.Id);
        }
Пример #2
0
        public static PeriodModel Next(this IEnumerable <PeriodModel> periods, PeriodModel current)
        {
            var last = periods.Last();

            if (last.Year == current.Year && last.Month == current.Month)
            {
                return(last);
            }

            var year  = current.Year;
            var month = current.Month;

            if (month == 12)
            {
                year  = year + 1;
                month = 1;
            }
            else
            {
                month = month + 1;
            }

            return(periods.Single(period => period.Year == year && period.Month == month));
        }
Пример #3
0
        public static PeriodModel Previous(this IEnumerable <PeriodModel> periods, PeriodModel current)
        {
            var first = periods.First();

            if (first.Year == current.Year && first.Month == current.Month)
            {
                return(first);
            }

            var year  = current.Year;
            var month = current.Month;

            if (month == 1)
            {
                year  = year - 1;
                month = 12;
            }
            else
            {
                month = month - 1;
            }

            return(periods.Single(period => period.Year == year && period.Month == month));
        }