view Agendas/trunk/src/Agendas.Web/Models/PersonaModel.cs @ 266:dba5d41bc7bf

BUG: Guardar persona con twitter ya existente genera error.
author juanjose.montesdeocaarbos
date Tue, 25 Oct 2011 23:22:10 -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("@");
        }
    }
}