bugs fix
This commit is contained in:
parent
599e9a8865
commit
84f9f63407
44 changed files with 560 additions and 92 deletions
|
@ -6,7 +6,7 @@ namespace WebsitePanel.WebDavPortal.CustomAttributes
|
|||
{
|
||||
public class PhoneNumberAttribute : RegularExpressionAttribute, IClientValidatable
|
||||
{
|
||||
public const string PhonePattern = @"^\+?(\d[\d-. ]+)?(\([\d-. ]+\))?[\d-. ]+\d$";
|
||||
public const string PhonePattern = @"^\+?\d+$";
|
||||
|
||||
public PhoneNumberAttribute()
|
||||
: base(PhonePattern)
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using WebsitePanel.WebDav.Core;
|
||||
|
||||
namespace WebsitePanel.WebDavPortal.CustomAttributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
|
||||
public class UniqueAdPhoneNumberAttribute : RemoteAttribute
|
||||
{
|
||||
|
||||
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
||||
{
|
||||
Type type = Assembly.GetExecutingAssembly()
|
||||
.GetTypes()
|
||||
.FirstOrDefault(validationtype => validationtype.Name == string.Format("{0}controller", this.RouteData["controller"].ToString()));
|
||||
|
||||
object response = null;
|
||||
|
||||
if (type != null)
|
||||
{
|
||||
MethodInfo method = type.GetMethods()
|
||||
.FirstOrDefault(callingMethod => callingMethod.Name.ToLower() == (string.Format("{0}", this.RouteData["action"]).ToString().ToLower()));
|
||||
|
||||
if (method != null)
|
||||
{
|
||||
object instance = Activator.CreateInstance(type);
|
||||
response = method.Invoke(instance, new [] { value });
|
||||
}
|
||||
}
|
||||
|
||||
if (response is bool)
|
||||
{
|
||||
var attributes =
|
||||
validationContext.ObjectType.GetProperty(validationContext.MemberName)
|
||||
.GetCustomAttributes(typeof(DisplayNameAttribute), true);
|
||||
|
||||
string displayName = attributes != null && attributes.Any()
|
||||
? (attributes[0] as DisplayNameAttribute).DisplayName
|
||||
: validationContext.DisplayName;
|
||||
|
||||
|
||||
return (bool)response ? ValidationResult.Success :
|
||||
new ValidationResult(string.Format(Resources.Messages.AlreadyInUse, displayName));
|
||||
}
|
||||
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
|
||||
public UniqueAdPhoneNumberAttribute(string routeName) : base(routeName) { }
|
||||
public UniqueAdPhoneNumberAttribute(string action, string controller) : base(action, controller) { }
|
||||
public UniqueAdPhoneNumberAttribute(string action, string controller,
|
||||
string area) : base(action, controller, area) { }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue