/// <summary> /// /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { _serialiser = request.GetDependencyScope().GetService(typeof(ISerialiseMessage <USAddress>)) as ISerialiseMessage <USAddress>; if (request.Method == HttpMethod.Post && request.RequestUri.Segments.Contains("xml")) { var requestContent = request.Content.ReadAsStringAsync().Result; var requestObject = Deserialize <PurchaseOrderType>(new XmlMediaTypeFormatter(), requestContent) as PurchaseOrderType; if (requestObject.confirmDate.Date != DateTime.Today.Date) { var xml = new XElement("root", @"<validation_errors>confirmation date wrong</validation_errors>").ToString(); var response = new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(xml, Encoding.UTF8, @"applicaton/xml") }; var tsc = new TaskCompletionSource <HttpResponseMessage>(); tsc.SetResult(response); return(tsc.Task); } } return(base.SendAsync(request, cancellationToken)); }
public VAlidator(ISerialiseMessage <PurchaseOrderType> serialiseMessage) { _serialiseMessage = serialiseMessage; RuleFor(type => type.confirmDate).NotNull().NotEmpty(); }