Example #1
0
        public void ChangeOrderState(OrderKeyModel orderModel, OrderState state)
        {
            using (var transaction = new TransactionScope(TransactionScopeOption.Required))
            {
                using (var mappers = new ManagementDataMapperContainer())
                {
                    var orderMapper = mappers.CustomerOrderMapper;

                    var order = orderMapper.Query().SingleOrDefault(o => o.ProductId == orderModel.ProductCode && o.CustomerId == orderModel.CustomerId && o.OrderDate == orderModel.OrderDate);

                    if (order == null)
                    {
                        throw new ArgumentException("Order doesn't exist!");
                    }

                    order.State = (int)state;
                    orderMapper.Update(order);

                    NotificationHelper.NotifyOrderChangedState(mappers.CustomerMapper.Get(orderModel.CustomerId),
                                                               mappers.ProductMapper.Get(orderModel.ProductCode),
                                                               state.ToString());

                }

                transaction.Complete();
            }
        }
Example #2
0
        public OrderModel GetOrder(OrderKeyModel orderModel)
        {
            using (var mappers = new ManagementDataMapperContainer())
            {
                var orderMapper = mappers.CustomerOrderMapper;

                return orderMapper.Query()
                    .Select(o =>
                        new OrderModel
                        {
                            ProductCode = o.ProductId,
                            CustomerId = o.CustomerId,
                            OrderDate = o.OrderDate,
                            Quantity = o.OrderAmount.Value,
                            State = o.State
                        })
                    .SingleOrDefault(o => o.ProductCode == orderModel.ProductCode && o.CustomerId == orderModel.CustomerId && o.OrderDate == orderModel.OrderDate);
            }
        }