view Agendas/trunk/src/Agendas.Web/Models/PersonaModel.cs @ 259:e6c041d8e1bf

Ticket #193.1: Al guardar (nuevo/modificar) una persona, que la cuenta de twitter no comience con @
author juanjose.montesdeocaarbos
date Thu, 20 Oct 2011 08:16:55 -0300
parents 730b80afa70d
children 8a2a58b5e2d6
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;
        }
    }

}