Esempio n. 1
0
        public virtual async Task AddOrder(Order order, CustomerActionTypeEnum customerActionType)
        {
            var actiontypes = await GetAllCustomerActionType();

            var actionType = actiontypes.Where(x => x.SystemKeyword == customerActionType.ToString()).FirstOrDefault();

            if (actionType?.Enabled == true)
            {
                var datetimeUtcNow = DateTime.UtcNow;
                var query          = from a in _customerActionRepository.Table
                                     where a.Active == true && a.ActionTypeId == actionType.Id &&
                                     datetimeUtcNow >= a.StartDateTimeUtc && datetimeUtcNow <= a.EndDateTimeUtc
                                     select a;

                foreach (var item in query.ToList())
                {
                    if (!UsedAction(item.Id, order.CustomerId))
                    {
                        var customer = await _customerService.GetCustomerById(order.CustomerId);

                        foreach (var orderItem in order.OrderItems)
                        {
                            var product = await _productService.GetProductById(orderItem.ProductId);

                            if (await Condition(item, product, orderItem.AttributesXml, customer, null, null))
                            {
                                await Reaction(item, customer, null, order);

                                break;
                            }
                        }
                    }
                }
            }
        }
        public virtual async Task AddOrder(Order order, CustomerActionTypeEnum customerActionType)
        {
            var actiontypes = await GetAllCustomerActionType();

            var actionType = actiontypes.Where(x => x.SystemKeyword == customerActionType.ToString()).FirstOrDefault();

            if (actionType?.Enabled == true)
            {
                var datetimeUtcNow = DateTime.UtcNow;
                var query          = from a in _customerActionRepository.Table
                                     where a.Active == true && a.ActionTypeId == actionType.Id &&
                                     datetimeUtcNow >= a.StartDateTimeUtc && datetimeUtcNow <= a.EndDateTimeUtc
                                     select a;

                foreach (var item in query.ToList())
                {
                    if (!UsedAction(item.Id, order.CustomerId))
                    {
                        foreach (var orderItem in order.OrderItems)
                        {
                            if (await _mediator.Send(new CustomerActionEventConditionCommand()
                            {
                                CustomerActionTypes = actiontypes,
                                Action = item,
                                ProductId = orderItem.ProductId,
                                CustomerId = order.CustomerId,
                                AttributesXml = orderItem.AttributesXml
                            }))
                            {
                                await _mediator.Send(new CustomerActionEventReactionCommand()
                                {
                                    CustomerActionTypes = actiontypes,
                                    Action     = item,
                                    Order      = order,
                                    CustomerId = order.CustomerId,
                                });

                                break;
                            }
                        }
                    }
                }
            }
        }