public void AddOrderItemToOrder(Product product, int count, ClientOrder order)
        {
            if(product==null)
                throw new ArgumentException("A product with the specified ID not found", "productId");
            if (count <= 0)
                throw new ArgumentException("Count should be greatest then zero", "count");

                ClientOrderItem existingOrderItem = order.Products.FirstOrDefault(p => p.Id == product.Id);
                if (existingOrderItem != null)
                {
                    existingOrderItem.Count += count;
                    Command command = CommandList.FirstOrDefault(c => c.Entity == existingOrderItem && c.FieldName == "Count" && c.CommandType == CommandType.Update);
                    if (command != null)
                    {
                        command.Value = existingOrderItem.Count;
                    }
                    else
                    {
                        CommandList.AddUpdateOrderItemCommand(existingOrderItem, "Count", existingOrderItem.Count);
                    }
                    order.Products.ResetItem(order.Products.IndexOf(existingOrderItem));
                }
                else
                {
                    ClientOrderItem orderItem = new ClientOrderItem(product.Id);
                    orderItem.Count = count;
                    orderItem.Price = product.Price.Price;
                    orderItem.Name = product.Name;
                    order.Products.Add(orderItem);
                    CommandList.AddCreateOrderItemCommand(orderItem);
                    CommandList.AddUpdateOrderItemCommand(orderItem, "Count", orderItem.Count);
                }
        }
        public static ClientOrderItem TranslateToClientOrderItem(OrderItem orderItem)
        {
            if (orderItem != null&&orderItem.Product!=null)
            {
                ClientOrderItem clientOrderItem = new ClientOrderItem(orderItem.Product.Id);
                clientOrderItem.Name = orderItem.Product.Name;
                clientOrderItem.Count = orderItem.Count;
                clientOrderItem.Price = orderItem.Product.Price.Price;

                return clientOrderItem;
            }
            return null;
        }
 public static OrderItem TranslateToOrderItem(ClientOrderItem clientOrderItem, Order order)
 {
     if (clientOrderItem != null)
     {
         OrderItem orderItem = new OrderItem();
         orderItem.Product = new Product();
         orderItem.Product.Id = clientOrderItem.Id;
         orderItem.Product.Name = clientOrderItem.Name;
         orderItem.Count = clientOrderItem.Count;
         orderItem.Order = order;
         return orderItem;
     }
     return null;
 }
 public static OrderItem TranslateToOrderItem(ClientOrderItem clientOrderItem)
 {
     return TranslateToOrderItem(clientOrderItem, null);
 }
 public void TranslateToOrderItemTest()
 {
     ClientOrderItem clientOrderItem = new ClientOrderItem(1)
     {
         Count = 10,
         Name = "Test product 1",
         Price = 100,
     };
     Order order = new Order();
     OrderItem orderItem = EntitiesTranslator.TranslateToOrderItem(clientOrderItem, order);
     Assert.AreEqual(orderItem.Product.Id, clientOrderItem.Id);
     Assert.AreEqual(orderItem.Count, clientOrderItem.Count);
     Assert.AreEqual(orderItem.Order, order);
     Assert.AreEqual(orderItem.Product.Name, clientOrderItem.Name);
 }
 public void RemoveOrderItemFromOrder(ClientOrderItem orderItem)
 {
     CommandList.AddRemoveOrderItemCommand(orderItem);
     customerEditOrderView.Order.Products.Remove(orderItem);
 }