Пример #1
0
        public static void AddOrderItemComment(Order order, int orderItemId, int userId, string comment)
        {
            OrderItemComment orderItemComment = OrderItemComment.New();

            orderItemComment.OrderItemId = orderItemId;
            orderItemComment.UserId      = userId;
            orderItemComment.CommentText = comment;
            orderItemComment.CommentDate = DateTime.Now;
            OrderItemComment.Update(orderItemComment);

            // Fire event
            if (NewUserOrderItemComment != null)
            {
                NewUserOrderItemComment(null, new OrderItemCommentEventArgs(order, orderItemComment));
            }
        }
Пример #2
0
        public static void ProcessOrderItems(EntityList <OrderItem> orderItems, User user)
        {
            if (orderItems.Count == 0)
            {
                throw new SystemException("No order items");
            }

            // Ensure that we have valid items
            ValidateOrderItemsForProcessing(orderItems);

            // Get the parent of the first order (all order items should be from the same order)
            Order order = orderItems[0].Order;

            // Create list to hold processed items
            EntityList <OrderItem> processedOrderItems = new EntityList <OrderItem>();

            // Flag to tell us whether we need to fire the 'order completion' event
            bool notifyIfComplete = false;

            // Iterate through all of the processed order items and save changes to database
            foreach (OrderItem orderItem in orderItems)
            {
                if (orderItem.IsDirty)
                {
                    notifyIfComplete = true;
                }

                // Update database
                OrderItem.Update(orderItem);

                // Save comments
                foreach (OrderItemComment orderItemComment in orderItem.NewOrderItemCommentList)
                {
                    // Save the comment
                    OrderItemComment.Update(orderItemComment);

                    // Fire event so user gets notified that a new comment has been made
                    if (NewAdminOrderItemComment != null)
                    {
                        NewAdminOrderItemComment(null, new OrderItemCommentEventArgs(order, orderItemComment));
                    }
                }

                // All new comments saved
                orderItem.NewOrderItemCommentList.Clear();

                switch (orderItem.OrderItemStatus)
                {
                case (OrderItemStatus.Approved):

                    // Order items which are approved are processed so add these to the processedOrderItems list
                    processedOrderItems.Add(orderItem);

                    // Log that a request for this asset was approved in the asset audit history
                    AuditLogManager.LogAssetAction(orderItem.AssetId, user, AuditAssetAction.ApprovedForDownload, string.Format("Approved for download for OrderId: {0} made by {1}", orderItem.OrderId, order.User.FullName));

                    // Log in user audit
                    AuditLogManager.LogUserAction(user, AuditUserAction.AuthoriseOrder, string.Format("Approved request for asset with AssetId: {0} for download in OrderId: {1} made by {2} (UserId: {3})", orderItem.AssetId, orderItem.OrderId, order.User.FullName, order.User.UserId));

                    break;

                case (OrderItemStatus.Rejected):

                    // Order items which are rejected are processed so add these to the processedOrderItems list
                    processedOrderItems.Add(orderItem);

                    // Log that a request for this asset was rejected in the asset audit history
                    AuditLogManager.LogAssetAction(orderItem.AssetId, user, AuditAssetAction.RejectedForDownload, string.Format("Rejected for download for OrderId: {0} made by {1}.  Reason: {2}", orderItem.OrderId, order.User.FullName, orderItem.LastComment));

                    // Log in user audit
                    AuditLogManager.LogUserAction(user, AuditUserAction.AuthoriseOrder, string.Format("Rejected request for asset with AssetId: {0} for download in OrderId: {1} made by {2} (UserId: {3})", orderItem.AssetId, orderItem.OrderId, order.User.FullName, order.User.UserId));

                    break;
                }
            }

            // Complete the order if everything has been processed
            if (AllOrderItemsProcessed(order))
            {
                CompleteOrder(order);
            }
            else
            {
                // Otherwise, fire the order items processed event to trigger
                // any notifications to this user that order items have been processed.
                // We only want to fire this if order items have actually been changed though
                // so we look through the order items and check that at least one is dirty

                if (notifyIfComplete)
                {
                    if (OrderItemsProcessed != null)
                    {
                        OrderItemsProcessed(null, new OrderItemEventArgs(order, processedOrderItems));
                    }
                }
            }

            // Update user audit with how many order items were processed in which order
            AuditLogManager.LogUserAction(user, AuditUserAction.AuthoriseOrder, string.Format("Processed {0} items in order with OrderId: {1}", processedOrderItems.Count, order.OrderId));
        }