FlashMessageExtensions.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Web;
  2. using System.Web.Mvc;
  3. namespace CD67.FicheCollege.MVC.Internal
  4. {
  5. internal static class FlashMessageExtensions
  6. {
  7. public static Controller Error(this Controller result, string message)
  8. {
  9. CreateFlashMessage(Notification.Error, message);
  10. return result;
  11. }
  12. public static Controller Warning(this Controller result, string message)
  13. {
  14. CreateFlashMessage(Notification.Warning, message);
  15. return result;
  16. }
  17. public static Controller Success(this Controller result, string message)
  18. {
  19. CreateFlashMessage(Notification.Success, message);
  20. return result;
  21. }
  22. public static Controller Information(this Controller result, string message)
  23. {
  24. CreateFlashMessage(Notification.Info, message);
  25. return result;
  26. }
  27. private static void CreateFlashMessage(Notification notification, string message)
  28. {
  29. System.Web.HttpContext.Current.Session[notification.ToString()] = message;
  30. }
  31. private enum Notification
  32. {
  33. Error,
  34. Warning,
  35. Success,
  36. Info
  37. }
  38. }
  39. }