public IHttpActionResult GetInvoicePdf(string orderNumber) { var searchCriteria = AbstractTypeFactory <CustomerOrderSearchCriteria> .TryCreateInstance(); searchCriteria.Number = orderNumber; searchCriteria.Take = 1; var order = _searchService.SearchCustomerOrders(searchCriteria).Results.FirstOrDefault(); if (order == null) { throw new InvalidOperationException($"Cannot find order with number {orderNumber}"); } var invoice = _notificationManager.GetNewNotification <InvoiceEmailNotification>(order.StoreId, "Store", order.LanguageCode); invoice.CustomerOrder = order; _notificationTemplateResolver.ResolveTemplate(invoice); var stream = new MemoryStream(); var pdf = PdfGenerator.GeneratePdf(invoice.Body, PdfSharp.PageSize.A4); pdf.Save(stream, false); stream.Seek(0, SeekOrigin.Begin); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(stream) }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); return(ResponseMessage(result)); }
public IHttpActionResult GetInvoicePdf(string orderNumber) { var oderSearchResult = _searchService.SearchCustomerOrders(new CustomerOrderSearchCriteria { Number = orderNumber, Take = 1 }); var order = oderSearchResult.Results.FirstOrDefault(); if (order == null) { throw new NullReferenceException("order not found"); } var invoice = _notificationManager.GetNewNotification(nameof(Invoice), null, null, "en-US"); ((Invoice)invoice).Order = order; _notificationTemplateResolver.ResolveTemplate(invoice); var stream = new MemoryStream(); var pdf = PdfGenerator.GeneratePdf(invoice.Body, PdfSharp.PageSize.A4); pdf.Save(stream, false); stream.Seek(0, SeekOrigin.Begin); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(stream) }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); return(ResponseMessage(result)); }
public IHttpActionResult RenderNotificationContent(webModels.TestNotificationRequest request) { var retVal = new webModels.RenderNotificationContentResult(); var notification = _notificationManager.GetNewNotification(request.Type, request.ObjectId, request.ObjectTypeId, request.Language); foreach (var param in request.NotificationParameters) { var property = notification.GetType().GetProperty(param.Key); var jObject = param.Value as Newtonsoft.Json.Linq.JObject; if (jObject != null) { property.SetValue(notification, jObject.ToObject <Dictionary <string, string> >()); } else { property.SetValue(notification, param.Value); } } _eventTemplateResolver.ResolveTemplate(notification); retVal.Subject = notification.Subject; retVal.Body = notification.Body; return(Ok(retVal)); }
public IHttpActionResult ResolveNotification([FromBody] List <KeyValuePair <string, string> > parameters, string type, string objectId, string objectTypeId, string language) { var notification = _notificationManager.GetNewNotification(type, objectId, objectTypeId, language); foreach (var param in parameters) { var property = notification.GetType().GetProperty(param.Key); property.SetValue(notification, param.Value); } _notificationTemplateResolver.ResolveTemplate(notification); return(Ok(notification.ToWebModel())); }
public IHttpActionResult RenderNotificationContent(webModels.TestNotificationRequest request) { var retVal = new webModels.RenderNotificationContentResult(); var notification = _notificationManager.GetNewNotification(request.Type, request.ObjectId, request.ObjectTypeId, request.Language); foreach (var param in request.NotificationParameters) { SetValue(notification, param); } _eventTemplateResolver.ResolveTemplate(notification); retVal.Subject = notification.Subject; retVal.Body = notification.Body; return(Ok(retVal)); }
public IHttpActionResult RenderNotificationContent([FromBody] List <KeyValuePair <string, string> > parameters, string type, string objectId, string objectTypeId, string language) { var retVal = new webModels.RenderNotificationContentResult(); var notification = _notificationManager.GetNewNotification(type, objectId, objectTypeId, language); foreach (var param in parameters) { var property = notification.GetType().GetProperty(param.Key); property.SetValue(notification, param.Value); } _eventTemplateResolver.ResolveTemplate(notification); retVal.Subject = notification.Subject; retVal.Body = notification.Body; return(Ok(retVal)); }
public async Task <IHttpActionResult> GetInvoicePdf(string orderNumber) { var searchCriteria = AbstractTypeFactory <CustomerOrderSearchCriteria> .TryCreateInstance(); var userName = User.Identity.Name; var user = await _securityService.FindByNameAsync(userName, UserDetails.Reduced); var responseGroup = OrderReadPricesPermission.ApplyResponseGroupFiltering(user, _securityService.GetUserPermissions(userName), null); searchCriteria.Number = orderNumber; searchCriteria.Take = 1; searchCriteria.ResponseGroup = responseGroup; var order = _searchService.SearchCustomerOrders(searchCriteria).Results.FirstOrDefault(); if (order == null) { throw new InvalidOperationException($"Cannot find order with number {orderNumber}"); } var invoice = _notificationManager.GetNewNotification <InvoiceEmailNotification>(order.StoreId, "Store", order.LanguageCode); invoice.CustomerOrder = order; _notificationTemplateResolver.ResolveTemplate(invoice); var stream = new MemoryStream(); var pdf = PdfGenerator.GeneratePdf(invoice.Body, PdfSharp.PageSize.A4); pdf.Save(stream, false); stream.Seek(0, SeekOrigin.Begin); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(stream) }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); return(ResponseMessage(result)); }
private void ResolveTemplate(Core.Notifications.Notification notification) { _resolver.ResolveTemplate(notification); }
private void ResolveTemplate(Core.Notification.Notification notification) { GetNewNotification(notification.GetType().Name, notification.ObjectId, notification.ObjectTypeId, notification.Language); _resolver.ResolveTemplate(notification); }
private void ResolveTemplate(Core.Notification.Notification notification) { SetNotificationTemplate(notification); _resolver.ResolveTemplate(notification); }