Avatar
mira.vezir
Člen
Avatar
mira.vezir:

Dobry den mohl by mi nekdo poradit?
pouzivam v2012 mvc4
Potreboval bych vytvorit vlastni account a ne ktery se vytvari jako defaultni. Dekuju
muj model vypada takto:

namespace OnlineSurgery.Models
{
    public class MaxWordsAttribute : ValidationAttribute
    {
        public MaxWordsAttribute(int maxWords)
        : base("{0} has too many words.")
        {
            _maxWords = maxWords;
        }
        protected override ValidationResult IsValid(
            object value, ValidationContext validationContext)
        {
            if (value != null)
            {
                var valueAsString = value.ToString();
                if (valueAsString.Split(' ').Length > _maxWords)
                {
                    var errorMessage = FormatErrorMessage(validationContext.DisplayName);
                    return new ValidationResult(errorMessage);
                }
            }
            return ValidationResult.Success;
        }
        private readonly int _maxWords;
    }

    public class User
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int UserId { get; set; }

        [Required]
        [DataType(DataType.Text)]
        [MaxWords(1)]
        [Display(Name = "User name")]
        public string UserName { get; set; }

        [Required]
        [DataType(DataType.Text)]
        [Display(Name = "Title")]
        public string Title { get; set; }

        [Required]
        [DataType(DataType.Text)]
        [Display(Name = "First Name")]
        public string FirstName { get; set; }

        [Required]
        [DataType(DataType.Text)]
        [Display(Name = "Last Name")]
        public string LastName { get; set; }

        [Required]
        //[StringLength(100, ErrorMessage = "The {0} must be at least {1} characters long.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }

        //[DataType(DataType.Password)]
        //[Display(Name = "Confirm password")]
        //[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
        //public string ConfirmPassword { get; set; }

        [Required]
        [DataType(DataType.PhoneNumber)]
        [Display(Name = "Phone")]
        public string Phone { get; set; }

        [Required]
        [DataType(DataType.Text)]
        [Display(Name = "First line of address")]
        public string AddressLine { get; set; }

        [Required]
        [DataType(DataType.PostalCode)]
        //[PostCode(ErrorMessage = "PostCode is not valid")]
        [Display(Name = "Post Code")]
        public string PostCode { get; set; }

        [DataType(DataType.Date)]
        [Display(Name = "DOB => dd/mm/yyyy")]
        public DateTime DOB { get; set; }

        [Required]
        [DataType(DataType.EmailAddress)]
        [Display(Name = "Email address")]
        public string Email { get; set; }

    }
    public class PostCodeAttribute : RegularExpressionAttribute
    {
        public PostCodeAttribute()
            : base(
                @"^([A-Z])(\d\d)(\d)([A-Z][A-Z])$")
        {
            ErrorMessage = "PostCode is invalid";
        }
    }
    public class EmailAttribute : RegularExpressionAttribute
    {
        public EmailAttribute()
            : base(
               @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
     + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
                                [0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
     + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
                                [0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
     + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$")
        {
            ErrorMessage = "PostCode is invalid";
        }
    }


}
Editováno 1.5.2013 16:56
 
Odpovědět 1.5.2013 16:43
Avatar
Odpovídá na mira.vezir
Luboš Běhounek (Satik):

tag code, cohle nikdo cist nebude :)

Nahoru Odpovědět 1.5.2013 16:45
:)
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 2 zpráv z 2.