public IViewComponentResult Invoke(DateTime currentDate, string action, string controller) { var monthYearModel = new MonthYearSelectionModel { CurrentDate = currentDate, Action = action, Controller = controller }; return(View(monthYearModel)); }
public static MvcHtmlString PSMonthYearSelection(this HtmlHelper htmlHelper, string id) { MonthYearSelectionModel requestModel = new MonthYearSelectionModel { ID = id, MonthYearOptions = MonthYearSelectionOptions.Last5Years }; MonthYearSelectionModel model = MonthYearSelectionController.GetMonthYearSelectionModel(requestModel); return(htmlHelper.Partial("~/Controls/MonthYear/Views/MonthYear.cshtml", model)); }
public static MonthYearSelectionModel GetMonthYearSelectionModel(MonthYearSelectionModel model) { var yearList = new List <int>(); switch (model.MonthYearOptions) { case MonthYearSelectionOptions.All: for (int y = model.MinYear; y <= model.MaxYear; y++) { yearList.Add(y); } break; case MonthYearSelectionOptions.Past: for (int y = model.MinYear; y <= DateTime.Today.Year; y++) { yearList.Add(y); } break; case MonthYearSelectionOptions.NextYear: for (int y = model.MinYear; y <= DateTime.Today.Year + 1; y++) { yearList.Add(y); } break; case MonthYearSelectionOptions.LastYear: for (int y = DateTime.Today.Year - 1; y <= DateTime.Today.Year; y++) { yearList.Add(y); } break; case MonthYearSelectionOptions.Last2Years: for (int y = DateTime.Today.Year - 2; y <= DateTime.Today.Year; y++) { yearList.Add(y); } break; case MonthYearSelectionOptions.Last5Years: for (int y = DateTime.Today.Year - 5; y <= DateTime.Today.Year; y++) { yearList.Add(y); } break; case MonthYearSelectionOptions.Span10Years: for (int y = DateTime.Today.Year - 5; y <= DateTime.Today.Year + 5; y++) { yearList.Add(y); } break; } // Initial values model.Year = DateTime.Today.Year; model.Month = DateTime.Today.Month; // Month list var monthList = Enumerable.Range(1, 12).Select(i => new { MonthNumber = i, MonthName = DateTimeFormatInfo.CurrentInfo.GetMonthName(i) }).ToList(); model.YearSelectList = yearList.ToSelectList(x => x.ToString(), x => x.ToString(), model.Year.ToString()); model.MonthSelectList = monthList.ToSelectList(x => x.MonthName.ToString(), x => x.MonthNumber.ToString(), model.Month.ToString()); return(model); }
public ActionResult MonthYearSelection(MonthYearSelectionModel requestModel) { var model = GetMonthYearSelectionModel(requestModel); return(PartialView(model)); }
public static MvcHtmlString PSMonthYearSelection(this HtmlHelper htmlHelper, MonthYearSelectionModel requestModel) { MonthYearSelectionModel model = MonthYearSelectionController.GetMonthYearSelectionModel(requestModel); return(htmlHelper.Partial("~/Controls/MonthYear/Views/MonthYear.cshtml", model)); }