view Agendas/trunk/src/Agendas.Web/Controllers/ControllerMessageExtensions.cs @ 284:79942e030118

#123: Patrocinadores de las vans: Se verifica que para publicar una Van, debe tener al menos un Patrocinador.
author juanjose.montesdeocaarbos
date Wed, 28 Dec 2011 09:35:27 -0300
parents 7ef7e4bb71f6
children
line wrap: on
line source

using System;
using System.Web.Mvc;

namespace AltNetHispano.Agendas.Web.Controllers
{
	public static class ControllerMessageExtensions
	{
		public static void AddError(this Controller controller, string mensaje)
		{
			AddMessage(controller, "error", mensaje);
		}

		public static void AddNotification(this Controller controller, string mensaje)
		{
			AddMessage(controller, "notification", mensaje);
		}

		public static void AddWarning(this Controller controller, string mensaje)
		{
			AddMessage(controller, "warning", mensaje);
		}

		#region protected and private members

		private static void AddMessage(Controller controller, string key, string mensaje)
		{
			if (controller == null) throw new ArgumentNullException("controller");
			if (key == null) throw new ArgumentNullException("key");
			if (mensaje == null) throw new ArgumentNullException("mensaje");

			if (mensaje == string.Empty) return;

			var mensajes = mensaje.Contains("\n") ? mensaje.Replace("\r", string.Empty).Split('\n') : new[] {mensaje};

			foreach (var m in mensajes)
			{
				if (controller.TempData.ContainsKey(key))
					controller.TempData[key] += "<br />";
				controller.TempData[key] += m;
			}
		}

		#endregion
	}
}