I'm trying to achieve a thin controller, and I started out with a thin controller but over time as the project has progressed the controller has got more complex. Could you please review the following code and let me know if the controller is still considered a thin controller or whether any of the code should be moved out into another class?
public class NavigationController : WebReportControllerBase
{
private readonly INavigationService _service;
public NavigationController(INavigationService service)
{
_service = service;
}
internal INavigationService Service
{
get
{
return _service;
}
}
public ActionResult Browse(NavigationPanelInputModel inputModel)
{
var item = inputModel.Item ?? "Category";
var navigationPanelViewModel = new NavigationPanelViewModel();
navigationPanelViewModel.Title = "Browse";
navigationPanelViewModel.NavigationLevel = Service.GetChildLevel<NavigationPanel>(item, "Browse");
if (item != "Category")
{
navigationPanelViewModel.NavigationLevel.AllowFiltering = true;
}
var viewModel = new NavigationBarOverlayViewModel
{
ViewModel = navigationPanelViewModel,
View = "NavigationPanelContainer",
CssClass = "browse"
};
if (Request.IsAjaxRequest()) {
if (inputModel.Item == null)
{
return PartialView("NavigationBarOverlay", viewModel);
}
else
{
return PartialView("~/Areas/WebReport/Views/Shared/DisplayTemplates/NavigationPanel.cshtml", navigationPanelViewModel.NavigationLevel);
}
}
else
{
return View("PageOverlay", viewModel);
}
}
public ActionResult Reports(NavigationPanelInputModel inputModel)
{
var item = inputModel.Item ?? "InitialList";
var navigationPanelViewModel = new NavigationPanelViewModel();
navigationPanelViewModel.Title = "Reports";
navigationPanelViewModel.NavigationLevel = Service.GetChildLevel<NavigationPanel>(item, "Reports");
var viewModel = new NavigationBarOverlayViewModel
{
ViewModel = navigationPanelViewModel,
View = "NavigationPanelContainer",
CssClass = "reports"
};
return View("PageOverlay", viewModel);
}
public ActionResult PeerGroups(NavigationPanelInputModel inputModel)
{
var item = inputModel.Item ?? "InitialList";
var navigationPanelViewModel = new NavigationPanelViewModel();
navigationPanelViewModel.Title = "Peer Groups";
navigationPanelViewModel.NavigationLevel = Service.GetChildLevel<NavigationPanel>(item, "PeerGroups");
var viewModel = new NavigationBarOverlayViewModel
{
ViewModel = navigationPanelViewModel,
View = "NavigationPanelContainer",
CssClass = "peer-groups"
};
if (Request.IsAjaxRequest())
{
if (inputModel.Item == null)
{
return PartialView("NavigationBarOverlay", viewModel);
}
else
{
return PartialView("~/Areas/WebReport/Views/Shared/DisplayTemplates/NavigationPanel.cshtml", navigationPanelViewModel.NavigationLevel);
}
}
else
{
return View("PageOverlay", viewModel);
}
}
public ActionResult MyProfile(NavigationPanelInputModel inputModel)
{
var item = inputModel.Item ?? "InitialList";
var navigationPanelViewModel = new NavigationPanelViewModel();
navigationPanelViewModel.Title = "My Profile";
navigationPanelViewModel.NavigationLevel = Service.GetChildLevel<NavigationPanel>(item, "MyProfile");
var viewModel = new NavigationBarOverlayViewModel
{
ViewModel = navigationPanelViewModel,
View = "NavigationPanelContainer",
CssClass = "my-profile"
};
if (Request.IsAjaxRequest())
{
return PartialView("NavigationBarOverlay", viewModel);
}
else
{
return View("PageOverlay", viewModel);
}
}
}