Combine layouts
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace MileageTraker.Web.Utility
|
||||
{
|
||||
public class ActionLogAttribute : ActionFilterAttribute
|
||||
{
|
||||
public override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
if (filterContext != null)
|
||||
{
|
||||
var controller = filterContext.RouteData.Values["controller"].ToString();
|
||||
var action = filterContext.RouteData.Values["action"].ToString();
|
||||
var loggerName = string.Format("{0}Controller.{1}", controller, action);
|
||||
var @params = string.Join(", ", filterContext.ActionParameters.Select(i => i.Key + ": " + i.Value));
|
||||
|
||||
var hostAddress = "UserHostAddress: " + filterContext.HttpContext.Request.UserHostAddress;
|
||||
|
||||
log4net.LogManager.GetLogger(loggerName).Info(hostAddress + ", " + @params);
|
||||
}
|
||||
base.OnActionExecuting(filterContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using MileageTraker.Web.Models;
|
||||
|
||||
namespace MileageTraker.Web.Utility
|
||||
{
|
||||
@@ -13,7 +13,10 @@ namespace MileageTraker.Web.Utility
|
||||
{
|
||||
public static string Wordify(this string str)
|
||||
{
|
||||
return str.Aggregate(string.Empty, (current, c) => current + (char.IsUpper(c) ? " " + c : c.ToString()));
|
||||
return str.Aggregate(
|
||||
String.Empty,
|
||||
(current, c) =>
|
||||
current + (Char.IsUpper(c) ? " " + c : c.ToString()));
|
||||
}
|
||||
|
||||
private static T GetAttribute<T>(this Enum enumeration) where T : Attribute
|
||||
@@ -48,13 +51,14 @@ namespace MileageTraker.Web.Utility
|
||||
public static IEnumerable<SelectListItem> GetSelectListItems(this Enum enumeration)
|
||||
{
|
||||
var type = enumeration.GetType();
|
||||
return Enum.GetValues(type).OfType<Enum>().Select(e =>
|
||||
new SelectListItem
|
||||
{
|
||||
Text = e.GetDisplayName(),
|
||||
Value = e.ToString(),
|
||||
Selected = e.Equals(enumeration)
|
||||
});
|
||||
return Enum.GetValues(type)
|
||||
.OfType<Enum>().Select(e =>
|
||||
new SelectListItem
|
||||
{
|
||||
Text = e.GetDisplayName(),
|
||||
Value = e.ToString(),
|
||||
Selected = e.Equals(enumeration)
|
||||
});
|
||||
}
|
||||
|
||||
public static IEnumerable<SelectListItem> ToSelectList(this Type enumType, string selectedItem, string noItemSelected)
|
||||
@@ -148,12 +152,12 @@ namespace MileageTraker.Web.Utility
|
||||
public static string LowercaseFirst(string s)
|
||||
{
|
||||
// Check for empty string.
|
||||
if (string.IsNullOrEmpty(s))
|
||||
if (String.IsNullOrEmpty(s))
|
||||
{
|
||||
return string.Empty;
|
||||
return String.Empty;
|
||||
}
|
||||
// Return char and concat substring.
|
||||
return char.ToLower(s[0]) + s.Substring(1);
|
||||
return Char.ToLower(s[0]) + s.Substring(1);
|
||||
}
|
||||
|
||||
public static IEnumerable<int> GetNumbers()
|
||||
@@ -161,15 +165,22 @@ namespace MileageTraker.Web.Utility
|
||||
var i = 0;
|
||||
while (true) yield return i++;
|
||||
}
|
||||
|
||||
public static MvcHtmlString Concat(this MvcHtmlString f, MvcHtmlString s)
|
||||
{
|
||||
return MvcHtmlString.Create(f.ToString() + s);
|
||||
}
|
||||
|
||||
public static MvcHtmlString Concat(this MvcHtmlString f, string s)
|
||||
/// <summary>
|
||||
/// Users with activity date greater than this value are online
|
||||
/// </summary>
|
||||
public static DateTime UserOnlineThreshold()
|
||||
{
|
||||
return MvcHtmlString.Create(f + s);
|
||||
return DateTime.UtcNow.Subtract(
|
||||
TimeSpan.FromMinutes(
|
||||
Convert.ToDouble(
|
||||
System.Web.Security.Membership.UserIsOnlineTimeWindow)));
|
||||
}
|
||||
|
||||
public static bool IsOnline(this User user)
|
||||
{
|
||||
return user.LastActivityDate != null
|
||||
&& user.LastActivityDate > UserOnlineThreshold();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace MileageTraker.Web.Utility
|
||||
{
|
||||
public class DenyFutureDateAttribute : ValidationAttribute
|
||||
{
|
||||
public override bool IsValid(object value)
|
||||
{
|
||||
var date = DateTime.Parse(value.ToString());
|
||||
return date.Date <= DateTime.Today;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace MileageTraker.Web.Utility
|
||||
{
|
||||
public class DenyPreviousMonthDateAttribute : ValidationAttribute
|
||||
{
|
||||
public override bool IsValid(object value)
|
||||
{
|
||||
var date = DateTime.Parse(value.ToString());
|
||||
return date.Date >= GetCutoff();
|
||||
}
|
||||
|
||||
private static DateTime GetCutoff()
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
return today.AddMonths(-1).AddDays(-today.Day + 1); // last two months
|
||||
//if (today.Day > 10)
|
||||
// return today.AddDays(-today.Day); // beginning of this month
|
||||
//return today.AddMonths(-1).AddDays(-today.Day); // beginning of previous month
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace MileageTraker.Web.Utility
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
|
||||
public class FormatHintAttribute : Attribute
|
||||
{
|
||||
public string Text { get; private set; }
|
||||
|
||||
public FormatHintAttribute(string text)
|
||||
{
|
||||
Text = text;
|
||||
}
|
||||
}
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
|
||||
public class UnitsAttribute : Attribute
|
||||
{
|
||||
public string Text { get; private set; }
|
||||
|
||||
public UnitsAttribute(string text)
|
||||
{
|
||||
Text = text;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
|
||||
public class InputSizeAttribute : Attribute
|
||||
{
|
||||
public string Size { get; private set; }
|
||||
|
||||
public string ClassName { get { return "input-" + Size.ToLower(); } }
|
||||
|
||||
/// <summary>
|
||||
/// Specify width of input element
|
||||
/// </summary>
|
||||
/// <param name="size">mini, small, medium, large, xlarge, xxlarge</param>
|
||||
public InputSizeAttribute(string size)
|
||||
{
|
||||
Size = size;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
|
||||
public class NoEditLabelAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace MileageTraker.Web.Utility
|
||||
{
|
||||
public class HttpParamActionAttribute : ActionNameSelectorAttribute
|
||||
{
|
||||
public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
|
||||
{
|
||||
if (actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase))
|
||||
return true;
|
||||
|
||||
if (!actionName.Equals("Action", StringComparison.InvariantCultureIgnoreCase))
|
||||
return false;
|
||||
|
||||
var request = controllerContext.RequestContext.HttpContext.Request;
|
||||
return request[methodInfo.Name] != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user