private void SendNotification(SpecialOrderResponseModel specialorder) { Customer customer = _customerRepository.GetCustomerByCustomerNumber(specialorder.Header.CustomerNumber, specialorder.Header.BranchId); if (customer == null) { StringBuilder warningMessage = new StringBuilder(); warningMessage.AppendFormat("Could not find customer({0}-{1}) to send SpecialOrder Confirmation notification.", specialorder.Header.BranchId, specialorder.Header.CustomerNumber); warningMessage.AppendLine(); warningMessage.AppendLine(); warningMessage.AppendLine("SpecialOrder:"); warningMessage.AppendLine(JsonConvert.SerializeObject(specialorder)); _log.WriteWarningLog(warningMessage.ToString()); } else { List <Recipient> recipients = LoadRecipients(NotificationType.OrderConfirmation, customer); Message message = GetEmailMessageForNotification(specialorder, customer); // send messages to providers... if (recipients != null && recipients.Count > 0) { SendMessage(recipients, message); } } }
private Message GetEmailMessageForNotification(SpecialOrderResponseModel specialorder, Customer customer) { Message message = new Message(); MessageTemplateModel template = _messageTemplateLogic.ReadForKey(MESSAGE_TEMPLATE_SPECIALORDERCONFIRMATION); message.MessageSubject = template.Subject.Inject(new { OrderStatus = "SpecialOrder Confirmation", CustomerNumber = customer.CustomerNumber, CustomerName = customer.CustomerName }); StringBuilder header = _messageTemplateLogic.BuildHeader ("Your special order will arrive at the Ben E. Keith warehouse on the date below. " + "Your special order items will ship on your next order following the arrival date in our warehouse.", customer); message.MessageBody += template.Body.Inject(new { NotifHeader = header.ToString(), InvoiceNumber = specialorder.Item.InvoiceNumber, ShipDate = specialorder.Item.EstimatedArrival, Total = double.Parse(specialorder.Item.Price).ToString("f2"), ItemNumber = specialorder.Item.ItemNumber.ToString(), GTIN = specialorder.Item.GtinUpc, Source = specialorder.Header.ManufacturerName, Description = specialorder.Item.Description, Quantity = specialorder.Item.QuantityRequested }); message.BodyIsHtml = template.IsBodyHtml; message.CustomerNumber = customer.CustomerNumber; message.CustomerName = customer.CustomerName; message.BranchId = customer.CustomerBranch; message.NotificationType = NotificationType.OrderConfirmation; return(message); }
private void ProcessSpecialOrderItemUpdate(string rawOrder) { try { SpecialOrderResponseModel specialorder = JsonConvert.DeserializeObject <SpecialOrderResponseModel>(rawOrder); _log.WriteInformationLog(string.Format("Consuming specialorder update from queue for message ({0}) with status {1}", specialorder.MessageId, specialorder.Item.ItemStatusId)); // retry trying to find the record up to 3 times. some times an exception is thrown for a bad command definition, but then processes fine the next time EF.OrderHistoryDetail detail = Retry.Do <EF.OrderHistoryDetail>(() => FindOrderHistoryDetailForUpdate(specialorder), TimeSpan.FromSeconds(5), 3); if (detail != null) { // only process if we match the order specified on this system ProcessOrderHistoryDetailByUpdateStatus(specialorder, detail); } else { _log.WriteInformationLog(string.Format(" ({0}) Specialorder update from queue for message not an order on this system", specialorder.MessageId)); } // Always clear context at the end of a transaction _unitOfWork.ClearContext(); } catch (Exception ex) { _log.WriteErrorLog("ProcessSpecialOrderItemUpdate", ex); } }
private string CreateTestSample() { SpecialOrderResponseModel specialorder = new SpecialOrderResponseModel(); specialorder.Header = new ResponseHeader(); specialorder.Item = new ResponseItem(); return(JsonConvert.SerializeObject(specialorder)); }
private void UpdateOrder(SpecialOrderResponseModel specialorder, EF.OrderHistoryDetail detail) { EF.OrderHistoryHeader header = _headerRepo.ReadById(detail.OrderHistoryHeader.Id); header.DeliveryDate = specialorder.Item.EstimatedArrival; _headerRepo.Update(header); detail.ItemStatus = Constants.CONFIRMATION_DETAIL_FILLED_CODE; _detailRepo.Update(detail); _unitOfWork.SaveChanges(); }
//private void ProcessOrderHistoryDetailOnStatusUpdate(SpecialOrderResponseModel specialorder, EF.OrderHistoryDetail detail) { // //_log.WriteInformationLog(string.Format(" ({0}) InternalSpecialOrderLogic.ProcessOrderHistoryDetailOnStatusUpdate", specialorder.MessageId)); // switch(specialorder.Item.ItemStatusId) { // case Constants.SPECIALORDERITEM_NEW_STATUS_CODE: // detail.ItemStatus = Constants.SPECIALORDERITEM_NEW_STATUS_TRANSLATED_CODE; // break; // case Constants.SPECIALORDERITEM_ERR_STATUS_CODE: // detail.ItemStatus = Constants.SPECIALORDERITEM_ERR_STATUS_TRANSLATED_CODE; // break; // case Constants.SPECIALORDERITEM_2MF_STATUS_CODE: // detail.ItemStatus = Constants.SPECIALORDERITEM_2MF_STATUS_TRANSLATED_CODE; // break; // case Constants.SPECIALORDERITEM_REQ_STATUS_CODE: // detail.ItemStatus = Constants.SPECIALORDERITEM_REQ_STATUS_TRANSLATED_CODE; // break; // case Constants.SPECIALORDERITEM_ACC_STATUS_CODE: // detail.ItemStatus = Constants.SPECIALORDERITEM_ACC_STATUS_TRANSLATED_CODE; // break; // case Constants.SPECIALORDERITEM_APP_STATUS_CODE: // detail.ItemStatus = Constants.SPECIALORDERITEM_APP_STATUS_TRANSLATED_CODE; // break; // case Constants.SPECIALORDERITEM_DEL_STATUS_CODE: // detail.ItemStatus = Constants.SPECIALORDERITEM_DEL_STATUS_TRANSLATED_CODE; // break; // case Constants.SPECIALORDERITEM_HLD_STATUS_CODE: // detail.ItemStatus = Constants.SPECIALORDERITEM_HLD_STATUS_TRANSLATED_CODE; // break; // case Constants.SPECIALORDERITEM_RCV_STATUS_CODE: // detail.ItemStatus = Constants.SPECIALORDERITEM_RCV_STATUS_TRANSLATED_CODE; // break; // case Constants.SPECIALORDERITEM_R_H_STATUS_CODE: // detail.ItemStatus = Constants.SPECIALORDERITEM_R_H_STATUS_TRANSLATED_CODE; // break; // case Constants.SPECIALORDERITEM_ATT_STATUS_CODE: // detail.ItemStatus = Constants.SPECIALORDERITEM_ATT_STATUS_TRANSLATED_CODE; // break; // case Constants.SPECIALORDERITEM_PTL_STATUS_CODE: // detail.ItemStatus = Constants.SPECIALORDERITEM_PTL_STATUS_TRANSLATED_CODE; // break; // case Constants.SPECIALORDERITEM_SHP_STATUS_CODE: // detail.ItemStatus = Constants.SPECIALORDERITEM_SHP_STATUS_TRANSLATED_CODE; // break; // case Constants.SPECIALORDERITEM_PUR_STATUS_CODE: // detail.ItemStatus = Constants.SPECIALORDERITEM_PUR_STATUS_TRANSLATED_CODE; // break; // } // _detailRepo.Update(detail); // _unitOfWork.SaveChanges(); //} private void ProcessOrderHistoryDetailOnItemShipped (SpecialOrderResponseModel specialorder, EF.OrderHistoryDetail detail) { _log.WriteInformationLog (string.Format (" ({0}) InternalSpecialOrderLogic.ProcessOrderHistoryDetailOnStatusUpdate", specialorder.MessageId)); UpdateOrder(specialorder, detail); SendNotification(specialorder); }
private EF.OrderHistoryDetail FindOrderHistoryDetailForUpdate(SpecialOrderResponseModel specialorder) { EF.OrderHistoryDetail detail = null; // try to find detail by specialorderheaderid and linenumber if (!String.IsNullOrEmpty(specialorder.Header.RequestHeaderId) && !String.IsNullOrEmpty(specialorder.Item.LineNumber)) { detail = _detailRepo.Read(d => d.BranchId.Equals(specialorder.Header.BranchId, StringComparison.InvariantCultureIgnoreCase) && d.SpecialOrderHeaderId == specialorder.Header.RequestHeaderId && d.SpecialOrderLineNumber == specialorder.Item.LineNumber).FirstOrDefault(); } return(detail); }
private void ProcessOrderHistoryDetailByUpdateStatus(SpecialOrderResponseModel specialorder, EF.OrderHistoryDetail detail) { switch (specialorder.Item.ItemStatusId) { case Constants.SPECIALORDERITEM_DEL_STATUS_CODE: case Constants.SPECIALORDERITEM_PUR_STATUS_CODE: { ProcessOrderHistoryDetailOnDeletedOrPurgedStatusUpdate(detail); break; } case Constants.SPECIALORDERITEM_SHP_STATUS_CODE: { ProcessOrderHistoryDetailOnItemShipped(specialorder, detail); break; } //default: // not exposing any status from KSOS right now // { // ProcessOrderHistoryDetailOnStatusUpdate(specialorder, detail); // break; // } } }