view Agendas/trunk/src/Agendas.Web/Models/PersonaModel.cs @ 285:c8f378272407

#123: Patrocinadores de las vans.
author juanjose.montesdeocaarbos
date Sat, 31 Dec 2011 14:45:55 -0300
parents 5ddc574deeea
children
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]
        [Twitter]
        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]
        [Twitter]
        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; }
    }

    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public class TwitterAttribute: DataTypeAttribute
    {
        public TwitterAttribute()
            : base(DataType.Text)
        {
        }

        public override string FormatErrorMessage(string name)
        {

            if (ErrorMessage == null && ErrorMessageResourceName == null)
            {
                //TODO: Esto debe estar en el archivo de Recursos.
                const string TwitterAttribute_Invalid = "No debe ingresar el arroba al escribir la cuenta de twitter."; ;
                ErrorMessage = TwitterAttribute_Invalid;
            }
            return base.FormatErrorMessage(name);
        }

        public override bool IsValid(object value)
        {
            if (value == null)
            {
                return false;
            }

            return !((string)value).StartsWith("@");
        }
    }
}