Example #1
0
 public OrderItemModel Create(OrderItem item)
 {
     return new OrderItemModel()
         {
             Url = ControllerUrl(item),
             OrderUrl = ControllerUrl(item.Order),
             OrderID = item.OrderID,
             ItemID = item.ItemID,
             Quantity = item.Quantity,
             ClientID = item.Order.Client.ID,
             Product = Create(item.Product)
         };
 }
Example #2
0
        public OrderItem Parse(OrderItemModel model)
        {
            try
            {
                var entry = new OrderItem();

                //full object parsing
                if (!string.IsNullOrWhiteSpace(model.OrderUrl))
                {
                    if (model.ItemID != default(int))
                    {
                        entry.ItemID = model.ItemID;
                    }

                    var uri = new Uri(model.OrderUrl);
                    var orderId = int.Parse(uri.Segments.Last());
                    var order = _repo.GetOrder(model.ClientID, orderId);
                    var product = _repo.GetProduct(entry.ItemID);
                    entry.OrderID = orderId;
                    entry.Order = order;
                    entry.Product = product;
                }
                //partial parsing
                if (model.Quantity != default(int))
                {
                    entry.Quantity = model.Quantity;
                }
                return entry;
            }
            catch
            {
                return null;
            }
        }
Example #3
0
 private string ControllerUrl(OrderItem item)
 {
     return _urlHelper.Link("OrdersItems", new { orderid = item.Order.ID, id = item.ItemID });
 }
Example #4
0
 public KeyValuePair<string, decimal> CreateSummary(OrderItem item)
 {
     return new KeyValuePair<string, decimal>(item.Product.Name, item.Product.Price * item.Quantity);
 }