Esempio n. 1
0
        public void ProcessNotification(Core.Models.Messaging.Queue.BaseNotification notification)
        {
            try {
                if (notification.NotificationType != NotificationType.Eta)
                {
                    throw new ApplicationException("notification/handler type mismatch");
                }

                EtaNotification eta = (EtaNotification)notification;

                // load up recipients, customer and message
                eventLogRepository.WriteInformationLog("Received ETA Message with " + eta.Orders.Count + " orders");
                List <string> invoiceNumbers = eta.Orders.Select(x => x.OrderId).ToList();
                string        etaBranch      = eta.Orders[0].BranchId;
                var           orders         = orderHistoryRepository.Read(x => x.BranchId == etaBranch &&
                                                                           invoiceNumbers.Contains(x.InvoiceNumber)).ToList(); // get all orders for order ETAs

                foreach (OrderHistoryHeader order in orders)
                {
                    try {
                        var etaInfo = eta.Orders.Where(o => o.OrderId.Equals(order.InvoiceNumber) && o.BranchId.Equals(order.BranchId)).FirstOrDefault();

                        if (etaInfo != null)
                        {
                            //The information has a timezone offset that has already been accounted for, so we just need to ignore it
                            order.ScheduledDeliveryTime = String.IsNullOrEmpty(etaInfo.ScheduledTime) ? null : IgnoreOffsetTimeString(etaInfo.ScheduledTime);
                            order.EstimatedDeliveryTime = String.IsNullOrEmpty(etaInfo.EstimatedTime) ? null : IgnoreOffsetTimeString(etaInfo.EstimatedTime);
                            order.ActualDeliveryTime    = String.IsNullOrEmpty(etaInfo.ActualTime) ? null : IgnoreOffsetTimeString(etaInfo.ActualTime);
                            order.RouteNumber           = String.IsNullOrEmpty(etaInfo.RouteId) ? String.Empty : etaInfo.RouteId;
                            order.StopNumber            = String.IsNullOrEmpty(etaInfo.StopNumber) ? String.Empty : etaInfo.StopNumber;
                            order.DeliveryOutOfSequence = etaInfo.OutOfSequence == null ? false : etaInfo.OutOfSequence;
                        }
                    }
                    catch (Exception ex) {
                        eventLogRepository.WriteErrorLog("Error processing ETA notification for : " + order.InvoiceNumber + ".  " + ex.Message + ".  " + ex.StackTrace);
                    }
                }

                foreach (var order in orders)
                {
                    try {
                        orderHistoryRepository.Update(order);
                        System.Threading.Thread.Sleep(200);
                    }
                    catch (Exception ex) {
                        eventLogRepository.WriteErrorLog("Error saving ETA notification for : " + order.InvoiceNumber + ".  " + ex.Message + ".  " + ex.StackTrace);
                    }
                }

                unitOfWork.SaveChanges();
            }
            catch (Exception ex) {
                throw new Core.Exceptions.Queue.QueueDataError <BaseNotification>(notification, "EtaNotification:ProcessNotification", "Send ETA Notification", "There was an error processing an ETA notification", ex);
            }
        }
        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();
        }
        public void UpdateRelatedOrderNumber(string childOrderNumber, string parentOrderNumber)
        {
            var header = _headerRepo.ReadByConfirmationNumber(childOrderNumber, "B").FirstOrDefault();

            if (header != null)
            {
                header.RelatedControlNumber = parentOrderNumber;

                _headerRepo.Update(header);

                _unitOfWork.SaveChanges();
            }
        }