4

The code is self explanatory:

public class TooLateValidator : IApplicationStartupHandler
    {
        public TooLateValidator()
        {
            ContentService.Saving += ContentService_Saving;
        }

        private void ContentService_Saving(IContentService sender, Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IContent> e)
        {
            if(DateTime.Now.Hour > 21){

                e.Cancel = true;

                //validation message: "it's too late for that"
                // how do I throw this message to UI??

            }
        }
    }

I'm using Umbraco 6.

Juliano
  • 2,422
  • 21
  • 23

2 Answers2

2

As per the comments, this is a vague question and there are a number of possible solutions. It's hard to see what you need exactly but I will try and understand.

One of the outstanding bugs of Umbraco 6 was that the speech bubble would display custom messages but they would be overwritten immediately by Umbraco's own, but you can now do this easily (thanks to my friend Ali for the code source and works for me in v6.1.6).

using System.Web;
using System.Web.UI;
using Umbraco.Core;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.UI;
using Umbraco.Web.UI.Pages;

public class UmbracoEvents : ApplicationEventHandler
{
    protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        //Events
        ContentService.Created += Content_Created;
        ContentService.Saving += Content_Saving;
    }

    private void Content_Saving(IContentService sender, SaveEventArgs<IContent> e)
    {
        // 1 JavaScript 
        HttpContext.Current.Response.Write("<script>alert('Saved!');</script>");                        
        e.Cancel = true;

    }

    private void Content_Created(IContentService sender, NewEventArgs<IContent> e)
    {
        // 2 Umbraco speech bubble

        var clientTool = new ClientTools((Page)HttpContext.Current.CurrentHandler);
        clientTool.ShowSpeechBubble(SpeechBubbleIcon.Success, "Warning", "It is to late to do that!");
    }
}
csharpforevermore
  • 1,472
  • 15
  • 27
0

Try this

 //validation message: "it's too late for that"
 // how do I throw this message to UI??

 e.Messages.Add(new EventMessage("validation message", "it's too late for that", EventMessageType.Error));
Aaron
  • 1
  • 1