示例#1
0
 public ActionResult List(Models.Calendar.List vm)
 {
     return(Code.MvcHelper.Post(returnUrl: Url.Action("List", new
     {
         YearId = vm.YearId,
         FromDate = vm.FromDate,
         ToDate = vm.ToDate
     })));
 }
示例#2
0
        public ActionResult List()
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm = new Models.Calendar.List();
                vm.WeekList = WeekController.SelectList();

                vm.YearList = YearController.SelectList(Code.EnumHelper.YearType.Section);
                if (vm.YearId > 0 && vm.YearList.Exists(p => int.Parse(p.Value) == vm.YearId.Value))
                {
                    vm.YearList.ForEach(p => {
                        p.Selected = int.Parse(p.Value) == vm.YearId;
                    });
                }
                //获取当前激活学段的起始日期
                if (vm.FromDate == Code.DateHelper.MinDate || vm.ToDate.Value == Code.DateHelper.MinDate || vm.ToDate.Value < vm.FromDate.Value)
                {
                    var yearId = vm.YearId.HasValue ? vm.YearId.Value : 0;
                    if (yearId == 0)
                    {
                        yearId = vm.YearList.Where(p => p.Selected).Select(p => p.Value).FirstOrDefault().ConvertToInt();
                    }

                    var tbYear = YearController.SelectInfo(yearId);
                    if (tbYear != null)
                    {
                        vm.FromDate = tbYear.FromDate.HasValue ? tbYear.FromDate.Value : Code.DateHelper.MonthFirstDay;
                        vm.ToDate   = tbYear.ToDate.HasValue ? tbYear.ToDate.Value : DateTime.Now;
                    }
                    else
                    {
                        vm.FromDate = Code.DateHelper.MonthFirstDay;
                        vm.ToDate   = DateTime.Now;
                    }
                }
                vm.ToDate = vm.ToDate.Value.AddDays(1).AddSeconds(-1);

                if (vm.YearId == 0 && vm.YearList.Count > 0)
                {
                    vm.YearId = vm.YearList.OrderByDescending(d => d.Selected).FirstOrDefault().Value.ConvertToInt();
                }


                vm.DataList = (from p in db.Table <Entity.tbCalendar>()
                               where p.tbYear.Id == vm.YearId && p.CalendarDate >= vm.FromDate && p.CalendarDate <= vm.ToDate
                               select new Dto.Calendar.List()
                {
                    Id = p.Id,
                    tbWeekId = p.tbWeek.Id,
                    tbWeekName = p.tbWeek.WeekName,
                    tbYear = p.tbYear.YearName,
                    CalendarDate = p.CalendarDate,
                    Remark = p.Remark
                }).ToList();
                vm.DataList.ForEach(p =>
                {
                    p.tbWeekName = TbWeek[p.tbWeekId - 1];
                });
                return(View(vm));
            }
        }