<commit_before>﻿using System;
using System.Web.Mvc;
using System.Web.Routing;
using Glass.Mapper.Sc.Web.Mvc;
using Ignition.Core.Factories;
using Ignition.Core.Models;
using Ignition.Core.Models.BaseModels;
using Ignition.Core.Models.Page;
using Ignition.Core.Repositories;

namespace Ignition.Core.Mvc
{
	public abstract class IgnitionController : GlassController
	{
		public IAgentFactory AgentFactory { get; set; }
		public IParamsBase RenderingParameters { get; set; }
		public IModelBase RenderingItem { get; set; } 
		protected ItemContext Context { get; set; }

		protected IgnitionController(ItemContext context) : base(context)
		{
			if (context == null) throw new ArgumentNullException(nameof(context));
			Context = context;
		}

		protected override void Initialize(RequestContext requestContext)
		{
			base.Initialize(requestContext);
			SitecoreContext = Context;
			if (RouteData.Values.ContainsKey(CoreConstants.SitecoreFallThroughRoute))
				Context.DatasourceItem = GetLayoutItem<IModelBase>(false, true) ?? new NullModel();
			else
                Context.DatasourceItem = new NullModel();
			Context.RenderingParameters = new NullParams();
		}

		#region View Overloads

		protected ViewResult View<TViewModel>() where TViewModel : BaseViewModel, new()
		{
			return View<SimpleAgent<TViewModel>, TViewModel, NullParams>(new NullParams(), null);
		}

		protected ViewResult View<TViewModel>(object data) where TViewModel : BaseViewModel, new()
		{
			return View<SimpleAgent<TViewModel>, TViewModel, NullParams>(new NullParams(), data);
		}

		protected ViewResult View<TAgent, TViewModel>()
			where TAgent : Agent<TViewModel>
			where TViewModel : BaseViewModel, new()
		{
			return View<TAgent, TViewModel, NullParams>(new NullParams(), null);
		}

		protected ViewResult View<TAgent, TViewModel, TParams>(TParams param)
			where TAgent : Agent<TViewModel>
			where TViewModel : BaseViewModel, new()
			where TParams : IParamsBase
		{
			return View<TAgent, TViewModel, TParams>(param, null);
		}

		protected ViewResult View<TAgent, TViewModel>(object data)
			where TAgent : Agent<TViewModel>
			where TViewModel : BaseViewModel, new()
		{
			return View<TAgent, TViewModel, NullParams>(new NullParams(), data);
		}

		protected ViewResult View<TAgent, TViewModel, TParams>(TParams parameters, object viewdata)
			where TAgent : Agent<TViewModel>
			where TViewModel : BaseViewModel, new()
			where TParams : IParamsBase
		{
			var moduleName = GetType().Name.Replace(GetType().Namespace ?? string.Empty, string.Empty).Replace("Controller", string.Empty);

		    Context.ContextPage = GetContextItem<IPage>(true, true);
		    Context.ModuleWrapperName = moduleName;
		    Context.RenderingParameters = parameters;
		    Context.AgentParameters = viewdata;
			var agent = AgentFactory.CreateAgent<TAgent, TViewModel>(Context);
			agent.PopulateModel();
			return View(agent.ViewPath, agent.ViewModel);
		}
		#endregion

	}
}<commit_msg>adjusted for Params to be automatically added, reduced overloads for View<>()<commit_after>﻿using System;
using System.Web.Mvc;
using System.Web.Routing;
using Glass.Mapper.Sc.Web.Mvc;
using Ignition.Core.Factories;
using Ignition.Core.Models;
using Ignition.Core.Models.BaseModels;
using Ignition.Core.Models.Page;
using Ignition.Core.Repositories;

namespace Ignition.Core.Mvc
{
	public abstract class IgnitionController : GlassController
	{
		public IAgentFactory AgentFactory { get; set; }
		public IParamsBase RenderingParameters { get; set; }
		public IModelBase RenderingItem { get; set; } 
		protected ItemContext Context { get; set; }

		protected IgnitionController(ItemContext context) : base(context)
		{
			if (context == null) throw new ArgumentNullException(nameof(context));
			Context = context;
		}

		protected override void Initialize(RequestContext requestContext)
		{
			base.Initialize(requestContext);
			SitecoreContext = Context;
			if (RouteData.Values.ContainsKey(CoreConstants.SitecoreFallThroughRoute))
				Context.DatasourceItem = GetLayoutItem<IModelBase>(false, true) ?? new NullModel();
			else
                Context.DatasourceItem = new NullModel();
			Context.RenderingParameters = new NullParams();
		}

		#region View Overloads

		protected ViewResult View<TViewModel>() where TViewModel : BaseViewModel, new()
		{
			return View<SimpleAgent<TViewModel>, TViewModel, NullParams>(null);
		}

		protected ViewResult View<TAgent, TViewModel>()
			where TAgent : Agent<TViewModel>
			where TViewModel : BaseViewModel, new()
		{
			return View<TAgent, TViewModel, NullParams>(null);
		}

		protected ViewResult View<TAgent, TViewModel>(object agentParameters)
			where TAgent : Agent<TViewModel>
			where TViewModel : BaseViewModel, new()
		{
			return View<TAgent, TViewModel, NullParams>(agentParameters);
		}

	    protected ViewResult View<TAgent, TViewModel, TParams>()
	        where TAgent : Agent<TViewModel>
	        where TViewModel : BaseViewModel, new()
	        where TParams : class, IParamsBase
	    {
            return View<TAgent, TViewModel, TParams>(null);
        }

	    protected ViewResult View<TAgent, TViewModel, TParams>(object agentParameters)
			where TAgent : Agent<TViewModel>
			where TViewModel : BaseViewModel, new()
			where TParams : class, IParamsBase 
		{
			var moduleName = GetType().Name.Replace(GetType().Namespace ?? string.Empty, string.Empty).Replace("Controller", string.Empty);

		    Context.ContextPage = GetContextItem<IPage>(true, true);
		    Context.ModuleWrapperName = moduleName;
		    Context.RenderingParameters = GetRenderingParameters<TParams>();
		    Context.AgentParameters = agentParameters;
			var agent = AgentFactory.CreateAgent<TAgent, TViewModel>(Context);
			agent.PopulateModel();
			return View(agent.ViewPath, agent.ViewModel);
		}
		#endregion

	}
}
{'fraction_non_alphanumeric': 0.10139199175116, 'fraction_numerical': 0.0, 'mean_word_length': 4.66699123661149, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7472496', 'n_tokens_mistral': 1877, 'n_tokens_neox': 1629, 'n_words': 402}