示例#1
0
        public IList<Order> StoreAll(Customer customer, IList<Order> orders)
        {
            foreach (var order in orders)
            {
                if (order.Id == default(Guid))
                {
                    order.Id = Guid.NewGuid();
                }
                order.UserId = customer.Id;
                if (!customer.Orders.Contains(order.Id))
                {
                    customer.Orders.Add(order.Id);
                }

                foreach (var x in order.Lines)
                    _redisClient
                        .IncrementItemInSortedSet(RedisKeys.BestSellingItems,
                            (string) x.Item, (long) x.Quantity);

            }
            var orderIds = orders.Select(o => o.Id.ToString()).ToList();
            using (var transaction = _redisClient.CreateTransaction())
            {
                transaction.QueueCommand(c => c.Store(customer));
                transaction.QueueCommand(c => c.StoreAll(orders));
                transaction.QueueCommand(c => c.AddRangeToSet(RedisKeys
                    .GetCustomerOrdersReferenceKey(customer.Id),
                    orderIds));
                transaction.Commit();
            }

            return orders;
        }
        public Customer Store(Customer customer)
        {
            var typedClient = _redisClient.As<Customer>();

            if (customer.Id == default(Guid))
            {
                customer.Id = Guid.NewGuid();
            }
            return typedClient.Store(customer);
        }
示例#3
0
 public Order Store(Customer customer, Order order)
 {
     IList<Order> result = StoreAll(customer, new List<Order>() { order });
     return result.FirstOrDefault();
 }