using System.Web.Mvc;
using MileageTraker.Web.DAL;

namespace MileageTraker.Web.Attributes
{
	public class UserActivityAttribute : ActionFilterAttribute
	{
		public override void OnActionExecuting(ActionExecutingContext filterContext)
		{
			if (filterContext != null 
				&& filterContext.HttpContext != null 
				&& filterContext.HttpContext.User != null
				&& filterContext.HttpContext.User.Identity.Name != null)
			{
				using (var ds = new DataService())
				{
					ds.UpdateUserLastActivity(filterContext.HttpContext.User.Identity.Name);
				}
			}
			base.OnActionExecuting(filterContext);
		}
	}
}