changeset 117:7ef7e4bb71f6

manejo de mensajes al usuario
author Nelo@Kenia.neluz.int
date Sun, 19 Jun 2011 13:35:34 -0300
parents 53bcd338542b
children b74734a1a755
files Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj Agendas/trunk/src/Agendas.Web/Content/AltNetHispanoVans.css Agendas/trunk/src/Agendas.Web/Controllers/ControllerMessageExtensions.cs Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs Agendas/trunk/src/Agendas.Web/Views/Shared/_Layout.cshtml Agendas/trunk/src/Agendas.Web/Views/Shared/_Messages.cshtml
diffstat 6 files changed, 193 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj	Sun Jun 19 13:00:02 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj	Sun Jun 19 13:35:34 2011 -0300
@@ -62,6 +62,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Controllers\AccountController.cs" />
+    <Compile Include="Controllers\ControllerMessageExtensions.cs" />
     <Compile Include="Controllers\EventoController.cs" />
     <Compile Include="Controllers\HomeController.cs" />
     <Compile Include="Controllers\PerfilController.cs" />
@@ -86,6 +87,7 @@
     <Compile Include="Services\IMembershipService.cs" />
   </ItemGroup>
   <ItemGroup>
+    <Content Include="Content\AltNetHispanoVans.css" />
     <Content Include="Content\altnetlogo.png" />
     <Content Include="Content\question.jpg" />
     <Content Include="Content\twitter\sign-in-with-twitter-d-sm.png" />
@@ -199,6 +201,9 @@
   <ItemGroup>
     <Content Include="Views\Perfil\AddBuiltInAccount.cshtml" />
   </ItemGroup>
+  <ItemGroup>
+    <Content Include="Views\Shared\_Messages.cshtml" />
+  </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Web/Content/AltNetHispanoVans.css	Sun Jun 19 13:35:34 2011 -0300
@@ -0,0 +1,27 @@
+.errorbox {
+	padding: 5px 5px 5px 5px; 
+	width: 90%; 
+	text-align: center;
+	overflow: auto;
+	margin: 5px 25px 5px 25px;
+}
+
+.warningbox {
+	padding: 5px 5px 5px 5px; 
+	width: 90%; 
+	text-align: center;
+	overflow: auto;
+	margin: 5px 25px 5px 25px;
+	
+}
+
+.notificationbox {
+	padding: 5px 5px 5px 5px; 
+	width: 90%; 
+	text-align: center;
+	overflow: auto;
+	margin: 5px 25px 5px 25px;
+	border: 1px solid #1c7c13;
+	background-color: #d2f7cf;
+	color: #363636;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Web/Controllers/ControllerMessageExtensions.cs	Sun Jun 19 13:35:34 2011 -0300
@@ -0,0 +1,45 @@
+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
+	}
+}
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs	Sun Jun 19 13:00:02 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs	Sun Jun 19 13:35:34 2011 -0300
@@ -7,100 +7,109 @@
 
 namespace AltNetHispano.Agendas.Web.Controllers
 {
-  public class EventoController : Controller
-  {
-    public ActionResult Index()
-    {
-      var agenda = AgendaFactory.GetAgenda();
+	public class EventoController : Controller
+	{
+		public ActionResult Index()
+		{
+			var agenda = AgendaFactory.GetAgenda();
 
-	  var model = new EventoIndexModel
-	  {
-		  ProximosEventos = from e in agenda.GetEventosAgendados()
-							orderby e.Fecha
-							select new EventoDto
+			var model = new EventoIndexModel
 							{
-								Id = e.Id.ToString(),
-								Titulo = e.Titulo,
-								Fecha = e.Fecha.Value,
-								PuedeModificar = e.GetEstado().PuedePromover(Accion.Modificar),
-								PuedeConfirmar = e.GetEstado().PuedePromover(Accion.Confirmar),
-								PuedePublicar = e.GetEstado().PuedePromover(Accion.Publicar)
-							}
-	  };
+								ProximosEventos = from e in agenda.GetEventosAgendados()
+												  orderby e.Fecha
+												  select new EventoDto
+															{
+																Id = e.Id.ToString(),
+																Titulo = e.Titulo,
+																Fecha = e.Fecha.Value,
+																PuedeModificar = e.GetEstado().PuedePromover(Accion.Modificar),
+																PuedeConfirmar = e.GetEstado().PuedePromover(Accion.Confirmar),
+																PuedePublicar = e.GetEstado().PuedePromover(Accion.Publicar)
+															}
+							};
+			return View(model);
+		}
 
-      return View(model);
-    }
-
-    [Authorize]
-    public ActionResult New()
-    {
-      return View(new EventoNewModel());
-    }
+		[Authorize]
+		public ActionResult New()
+		{
+			return View(new EventoNewModel());
+		}
 
-    [HttpPost]
-    [Authorize]
-    public ActionResult New(EventoNewModel model)
-    {
-      if (ModelState.IsValid)
-      {
-        var agenda = AgendaFactory.GetAgenda();
+		[HttpPost]
+		[Authorize]
+		public ActionResult New(EventoNewModel model)
+		{
+			if (ModelState.IsValid)
+			{
+				var agenda = AgendaFactory.GetAgenda();
 
-        var r = agenda.Agendar(model.Titulo, model.Ponente, model.Fecha,
-          model.UrlInvitacion, (TipoEvento)model.Tipo);
-        if (r.Succeful)
-          return RedirectToAction("Index");
-        ModelState.AddModelError("error", r.ToString());
-      }
-      return View(model);
-    }
+				var r = agenda.Agendar(model.Titulo, model.Ponente, model.Fecha,
+				  model.UrlInvitacion, (TipoEvento)model.Tipo);
+				if (r.Succeful)
+				{
+					this.AddNotification("Datos guardados");
+					return RedirectToAction("Index");
+				}
+				ModelState.AddModelError("error", r.ToString());
+			}
+			return View(model);
+		}
 
-    [Authorize]
-    public ActionResult Edit(string id)
-    {
-      var agenda = AgendaFactory.GetAgenda();
-      var evento = agenda.GetEvento(new Guid(id));
+		[Authorize]
+		public ActionResult Edit(string id)
+		{
+			var agenda = AgendaFactory.GetAgenda();
+			var evento = agenda.GetEvento(new Guid(id));
 
-      var model = new EventoEditModel
-                    {
-                      Id = id,
-                      Titulo = evento.Titulo,
-                      Ponente = evento.Ponente != null ? evento.Ponente.Nombre : string.Empty,
-                      Fecha = evento.Fecha,
-                      UrlInvitacion = evento.UrlInvitacion
-                    };
-      return View(model);
-    }
+			var model = new EventoEditModel
+						  {
+							  Id = id,
+							  Titulo = evento.Titulo,
+							  Ponente = evento.Ponente != null ? evento.Ponente.Nombre : string.Empty,
+							  Fecha = evento.Fecha,
+							  UrlInvitacion = evento.UrlInvitacion
+						  };
+			return View(model);
+		}
 
-	[Authorize]
-	public ActionResult Confirm(string id)
-	{
-		var agenda = AgendaFactory.GetAgenda();
-		agenda.Confirmar(new Guid(id));
-		return RedirectToAction("Index");
-	}
+		[Authorize]
+		public ActionResult Confirm(string id)
+		{
+			var agenda = AgendaFactory.GetAgenda();
+			agenda.Confirmar(new Guid(id));
+
+			this.AddNotification("Evento confirmado");
+			return RedirectToAction("Index");
+		}
 
-	[Authorize]
-	public ActionResult Publish(string id)
-	{
-		var agenda = AgendaFactory.GetAgenda();
-		agenda.Publicar(new Guid(id), 0, string.Empty);
-		return RedirectToAction("Index");
-	}
+		[Authorize]
+		public ActionResult Publish(string id)
+		{
+			var agenda = AgendaFactory.GetAgenda();
+			agenda.Publicar(new Guid(id), 0, string.Empty);
+
+			this.AddNotification("Evento publicado");
+			return RedirectToAction("Index");
+		}
 
-    [HttpPost]
-    [Authorize]
-    public ActionResult Edit(EventoEditModel model)
-    {
-      if (ModelState.IsValid)
-      {
-        var agenda = AgendaFactory.GetAgenda();
+		[HttpPost]
+		[Authorize]
+		public ActionResult Edit(EventoEditModel model)
+		{
+			if (ModelState.IsValid)
+			{
+				var agenda = AgendaFactory.GetAgenda();
 
-        var r = agenda.ModificarEvento(new Guid(model.Id), model.Titulo, model.Ponente, model.Fecha.Value, model.UrlInvitacion);
-        if (r.Succeful)
-          return RedirectToAction("Index");
-        ModelState.AddModelError("error", r.ToString());
-      }
-      return View(model);
-    }
-  }
+				var r = agenda.ModificarEvento(new Guid(model.Id), model.Titulo, model.Ponente, model.Fecha.Value, model.UrlInvitacion);
+				if (r.Succeful)
+				{
+					this.AddNotification("datos guardados");
+					return RedirectToAction("Index");
+				}
+				ModelState.AddModelError("error", r.ToString());
+			}
+			return View(model);
+		}
+	}
 }
--- a/Agendas/trunk/src/Agendas.Web/Views/Shared/_Layout.cshtml	Sun Jun 19 13:00:02 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web/Views/Shared/_Layout.cshtml	Sun Jun 19 13:35:34 2011 -0300
@@ -3,10 +3,19 @@
 <head>
     <title>Gestión de VANs</title>
     <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
+    <link href="@Url.Content("~/Content/AltNetHispanoVans.css")" rel="stylesheet" type="text/css" />
     <script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
 
 	<link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
 	<script src="@Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"></script>
+
+    <script type="text/javascript">
+    	$(document).ready(function () {
+    		$(".errorbox").addClass("ui-state-error ui-corner-all");
+    		$(".warningbox").addClass("ui-state-highlight ui-corner-all");
+    		$(".notificationbox").addClass("ui-corner-all");
+    	});
+	</script>
 </head>
 
 <body>
@@ -26,6 +35,7 @@
         </div>
 
         <div id="main">
+			@Html.Partial("_Messages")
 			<div class="logo">
 				<img alt="logo" src="@Url.Content("~/Content/altnetlogo.png")" />
 			</div>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Web/Views/Shared/_Messages.cshtml	Sun Jun 19 13:35:34 2011 -0300
@@ -0,0 +1,12 @@
+@if (TempData.ContainsKey("error"))
+{
+	<div class="errorbox"><label>@TempData["error"]</label></div>
+}
+@if (TempData.ContainsKey("warning"))
+{
+	<div class="warningbox"><label>@TempData["warning"]</label></div>
+}
+@if (TempData.ContainsKey("notification"))
+{
+	<div class="notificationbox"><label>@TempData["notification"]</label></div>
+}
\ No newline at end of file