/// <summary>
        /// Method to check for a cart/changeorder being submitted
        /// </summary>
        public static bool CheckOrderBlock(UserProfile user, UserSelectedContext catalogInfo, Guid?cartId, string orderNumber,
                                           IPurchaseOrderRepository pORepository, IOrderHistoryHeaderRepsitory hHRepository, ICacheRepository cache)
        {
            if (cartId != null && orderNumber == null) // if we are given cartId but not orderNumber, check for cross-reference
            {
                string cachekey = string.Format("Cart2OrderId_{0}", cartId);
                orderNumber = cache.GetItem <string>(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, cachekey);
            }

            if (orderNumber != null && cartId == null) // if we are given an orderNumber but not cartId, we could be in changeorder, check for cross-reference
            {
                string cachekey       = string.Format("ChangeOrder_Order2NewOrderId_{0}", orderNumber);
                string newOrderNumber = cache.GetItem <string>(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, cachekey);
                if (newOrderNumber != null)
                {
                    orderNumber = newOrderNumber;
                }
            }

            EF.OrderHistoryHeader theEFOrder = null;

            Order theOrder = null;

            // to check, we need to build the order and look at its status.
            if (catalogInfo != null && orderNumber != null && hHRepository != null)
            {
                // We just get the header not the details for performance
                theEFOrder = hHRepository.Read(h => h.BranchId.Equals(catalogInfo.BranchId, StringComparison.InvariantCultureIgnoreCase) &&
                                               (h.ControlNumber.Equals(orderNumber))).FirstOrDefault();
            }

            if (theEFOrder == null && pORepository != null && orderNumber != null) // if we don't find a header, try and construct the order from the purchaseOrder
            {
                CS.PurchaseOrder po = pORepository.ReadPurchaseOrderByTrackingNumber(orderNumber);

                theOrder = po.ToOrder();
            }
            else
            {
                if (theEFOrder != null)
                {
                    theOrder = theEFOrder.ToOrder();
                }
            }

            // we provide for no block for sysadmin
            // block a pending or submitted order otherwise
            //if (user.RoleName.Equals("beksysadmin", StringComparison.CurrentCultureIgnoreCase) == false &&
            //    theOrder != null && ((theOrder.Status.Equals("Pending")) | (theOrder.Status.Equals("Submitted"))))
            if (theOrder != null)
            {
                if ((theOrder.Status.Equals("Pending")) | (theOrder.Status.Equals("Submitted")))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
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);
            }
        }
        /// <summary>
        /// Gets just the primary order details needed without the excess of item details or invoice status
        /// </summary>
        /// <param name="customerInfo"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        private List <Order> GetShallowOrderDetailInDateRange(UserSelectedContext customerInfo, DateTime startDate, DateTime endDate)
        {
            int numberOfDays = (endDate - startDate).Days + 1;
            var dateRange    = Enumerable.Range(0, numberOfDays).Select(d => startDate.AddDays(d).ToLongDateFormat());

            List <EF.OrderHistoryHeader> headers = _headerRepo.Read(h => h.BranchId.Equals(customerInfo.BranchId, StringComparison.InvariantCultureIgnoreCase) &&
                                                                    h.CustomerNumber.Equals(customerInfo.CustomerId) &&
                                                                    dateRange.Contains(h.DeliveryDate),
                                                                    i => i.OrderDetails)
                                                   .ToList();
            List <Order> orders = new List <Order>();

            foreach (EF.OrderHistoryHeader h in headers)
            {
                Order order = h.ToOrder();

                if (order.Items != null)
                {
                    order.OrderTotal = order.Items.Sum(i => i.LineTotal);
                }

                orders.Add(order);
            }

            // Leaving this code commented out in case we need further performance increases
            //Parallel.ForEach( headers, new ParallelOptions { MaxDegreeOfParallelism = 2 }, h => {
            //    Order order = h.ToOrder();

            //    if (order.Items != null) {
            //        order.OrderTotal = order.Items.AsParallel().WithDegreeOfParallelism(2).Sum(i => i.LineTotal);
            //    }

            //    orders.Add( order );
            //} );

            return(orders);
        }