Exemple #1
0
        public string Add(int id)
        {

            const string prefix = "В корзине ";

            if (WebSession.OrderItems.ContainsKey(id))
                WebSession.OrderItems[id].Quantity++;
            else
            {
                using (var context = new ShopContainer())
                {
                    var product = context.Product.Include("Category").First(p => p.Id == id);
                    OrderItem orderItem = new OrderItem
                    {
                        Description = product.Description,
                        ImageSource = product.ImageSource,
                        Price = product.Price,
                        ProductId = product.Id,
                        ProductName = product.Name,
                        Quantity = 1,
                        ProductTitle = product.Title,
                        CategoryName = product.Category.Name,
                        CategoryTitle = product.Category.Title
                    };

                    WebSession.OrderItems.Add(product.Id, orderItem);
                }
            }

            int quantity = WebSession.OrderItems.Sum(o => o.Value.Quantity);

            return prefix+" " + quantity +" "+ TextHelper.GetQuantitySufix(quantity);
            // WebSession.OrderItems.Sum(o => o.Value.Quantity);
        }
Exemple #2
0
        public int Add(int id)
        {
            if (WebSession.OrderItems.ContainsKey(id))
                WebSession.OrderItems[id].Quantity++;
            else
            {
                using (var context = new ShopContainer())
                {
                    var product = context.Product.Include("Category").Include("ProductImages").First(p => p.Id == id);
                    var image = product.ProductImages.Where(i => i.Default).FirstOrDefault();
                    OrderItem orderItem = new OrderItem
                                              {
                                                  Description = product.Description,
                                                  Image = (image != null) ? image.ImageSource : null,
                                                  Price = product.Price,
                                                  ProductId = product.Id,
                                                  ProductName = product.Name,
                                                  Quantity = 1,
                                                  Name = product.Title,
                                                  CategoryName = product.Category.Name
                                              };

                    WebSession.OrderItems.Add(product.Id, orderItem);
                }
            }
            return WebSession.OrderItems.Sum(o=>o.Value.Quantity);
        }
Exemple #3
0
 /// <summary>
 /// Create a new OrderItem object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="imageSource">Initial value of the ImageSource property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 /// <param name="productId">Initial value of the ProductId property.</param>
 /// <param name="quantity">Initial value of the Quantity property.</param>
 /// <param name="orderId">Initial value of the OrderId property.</param>
 public static OrderItem CreateOrderItem(global::System.Int32 id, global::System.String imageSource, global::System.Decimal price, global::System.Int32 productId, global::System.Int32 quantity, global::System.Int32 orderId)
 {
     OrderItem orderItem = new OrderItem();
     orderItem.Id = id;
     orderItem.ImageSource = imageSource;
     orderItem.Price = price;
     orderItem.ProductId = productId;
     orderItem.Quantity = quantity;
     orderItem.OrderId = orderId;
     return orderItem;
 }
Exemple #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the OrderItem EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrderItem(OrderItem orderItem)
 {
     base.AddObject("OrderItem", orderItem);
 }
Exemple #5
0
 /// <summary>
 /// Create a new OrderItem object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 /// <param name="quantity">Initial value of the Quantity property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="orderId">Initial value of the OrderId property.</param>
 public static OrderItem CreateOrderItem(global::System.Int32 id, global::System.Decimal price, global::System.Int32 quantity, global::System.String name, global::System.Int32 orderId)
 {
     OrderItem orderItem = new OrderItem();
     orderItem.Id = id;
     orderItem.Price = price;
     orderItem.Quantity = quantity;
     orderItem.Name = name;
     orderItem.OrderId = orderId;
     return orderItem;
 }