31 lines
945 B
C#
31 lines
945 B
C#
|
using Microsoft.Practices.Unity;
|
|||
|
using Microsoft.Practices.Unity.InterceptionExtension;
|
|||
|
using Portoa.Search;
|
|||
|
using VideoGameQuotes.Api;
|
|||
|
|
|||
|
namespace VideoGameQuotes.Web.Configuration {
|
|||
|
/// <summary>
|
|||
|
/// Call handler that deletes the search index whenever a quote is deleted
|
|||
|
/// </summary>
|
|||
|
public class DeleteSearchIndexCallHandler : ICallHandler {
|
|||
|
private readonly IUnityContainer container;
|
|||
|
|
|||
|
public DeleteSearchIndexCallHandler(IUnityContainer container) {
|
|||
|
this.container = container;
|
|||
|
}
|
|||
|
|
|||
|
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) {
|
|||
|
var quoteId = (int)input.Arguments[0];
|
|||
|
var returnValue = getNext()(input, getNext);
|
|||
|
if (returnValue.Exception != null) {
|
|||
|
return returnValue;
|
|||
|
}
|
|||
|
|
|||
|
container.Resolve<ISearchIndexBuilder<Quote, int>>().DeleteIndex(new Quote { Id = quoteId });
|
|||
|
|
|||
|
return returnValue;
|
|||
|
}
|
|||
|
|
|||
|
public int Order { get; set; }
|
|||
|
}
|
|||
|
}
|