view Agendas/trunk/src/Agendas.Web/Models/PersonaModel.cs @ 260:8a2a58b5e2d6

Ticket #193: Validar mail, validar urls de personas.
author juanjose.montesdeocaarbos
date Thu, 20 Oct 2011 08:27:52 -0300
parents e6c041d8e1bf
children 5ddc574deeea
line wrap: on
line source

using System;
using System.Collections.Generic;
//using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using DataAnnotationsExtensions;


namespace AltNetHispano.Agendas.Web.Models
{
    public class PersonaIndexModel{
        public IEnumerable<PersonaDto> Items { get; set; }
    }

    public class PersonaNewModel
    {
        [Required]
        public string Nombre { get; set; }

        [Required]
        [CustomValidation(typeof(PersonaValidation), "IsTwitterAccount")]
        public string Twitter { get; set; }

        [Required]
        [Email ]
        public string EMail { get; set; }

		[Url ]
    	public string Blog { get; set; }

		public string[] Roles { get; set; }
    }

    public class PersonaEditModel
    {
        [Required]
        [HiddenInput(DisplayValue = false)]
        public string Id { get; set; }

        [Required]
        public string Nombre { get; set; }

        [Required]
        [CustomValidation(typeof(PersonaValidation), "IsTwitterAccount")]
        public string Twitter { get; set; }

        [Required]
        [Email]
        public string EMail { get; set; }

        [Url]
    	public string Blog { get; set; }

		public string[] Roles { get; set; }
    }

    public class PersonaDto
    {
        public Guid Id { get; set; }
        public string Nombre { get; set; }
    }

    public class PersonaViewModel
    {
        [HiddenInput(DisplayValue = false)]
        public string Id { get; set; }

        [HiddenInput]
        public string Nombre { get; set; }

        [HiddenInput]
        public string Twitter { get; set; }

        [HiddenInput]
        public string EMail { get; set; }

        [HiddenInput]
        public string Blog { get; set; }
    }

    //TODO: Ver donde movemos esta clase.
    public class PersonaValidation
    {
        public static ValidationResult IsTwitterAccount(string value)
        {
            //[RegularExpression(@"^([\w\d\-\.]+)$")]
            return value.StartsWith("@")
                       ? new ValidationResult("No debe ingresar el arroba al escribir la cuenta de twitter.")
                       : ValidationResult.Success;
        }
    }

}