Skip to content

Instantly share code, notes, and snippets.

@davetheninja
Created September 16, 2009 12:51
Show Gist options
  • Save davetheninja/188025 to your computer and use it in GitHub Desktop.
Save davetheninja/188025 to your computer and use it in GitHub Desktop.
This has been written in notepad Mr Duffy, forgive me for any compilation errors hahaha
public class Flash
{
public void Flash(string message, FlashPriority priority)
{
Message = message;
Priority = priority;
}
public string Message {get; private set;}
public FlashPriority Priority {get; private set;}
}
public class FlashExtensions
{
public void SetFlash(this viewData obj, string message, FlashPriority priority)
{
if (viewData.Contains["FLASH"]) viewData.Remove["FLASH"];
viewData.Add("FLASH", new Flash(message, priority));
}
}
public enum FlashPriority
{
Success = 1,
Warning = 2,
Error = 3
}
public class MyController : Controller
{
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Edit(int id)
{
var player = repos.Get<Player>(id);
var model = Mapper.Map<Player, PlayerViewModel>(player);
return View(model);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(PlayerViewModel model)
{
var player = repos.Get<Player>(id);
player.FirstName = model.FirstName;
player.LastName = model.LastName;
if (player.IsValid())
repos.Save(Player);
else
ViewData.SetFlash("your an ideot", FlashPriority.Error);
return View(model);
}
}
namespace System.Web.Mvc.Html
{
// Write html helper for rendering flash message
// <%= Html.Flash() %>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment