Пример #1
0
 public int AddPrice(int carModelId, int productId, decimal amount)
 {
     Price newPrice = new Price{
         CarModelId = carModelId,
         ProductId = productId,
         Amount = amount,
         Date = DateTime.Now,
     };
     db.Prices.InsertOnSubmit(newPrice);
     Save();
     return newPrice.Id;
 }
Пример #2
0
        public ActionResult AddItemToShoppingCart(int productId, int? carId)
        {
            Product product = productRepository.Get(productId);

            if ((Session["cart"] == null)||(((List<OrderItem>)Session["cart"]).Count ==0))
            {
                Price price = new Price();
                if (product.IsService)
                {
                    Car car = customerRepository.GetCar(carId.Value);
                    price = product.CurrentServicePriceEntity(car.CarModelId.Value);
                }
                else
                {
                    price = product.CurrentPriceEntity;
                }
                OrderItem orderItem = new OrderItem
                {
                    Product = product,
                    Price = price,
                    Quantity = 1,
                    TotalPrice = price.Amount * 1
                };
                List<OrderItem> orderItems = new List<OrderItem>();
                orderItems.Add(orderItem);
                Session.Add("cart", orderItems);
            }
            else
            {
                if (((List<OrderItem>)Session["cart"]).Any(x => x.ProductId == productId))
                {
                    List<OrderItem> orderItems = (List<OrderItem>)Session["cart"];
                    OrderItem orderItem = orderItems.FirstOrDefault(x => x.ProductId == productId);
                    //orderItems.Remove(orderItem);
                    Price price = new Price();
                    if (product.IsService)
                    {
                        Car car = customerRepository.GetCar(carId.Value);
                        price = product.CurrentServicePriceEntity(car.CarModelId.Value);
                    }
                    else
                    {
                        price = product.CurrentPriceEntity;
                    }
                    orderItem.Quantity += 1;
                    orderItem.TotalPrice += price.Amount;

                    //orderItems.Add(orderItem);
                    Session.Remove("cart");
                    Session.Add("cart", orderItems);
                }
                else
                {
                    List<OrderItem> orderItems = (List<OrderItem>)Session["cart"];
                    Price price = new Price();
                    if (product.IsService)
                    {
                        Car car = customerRepository.GetCar(carId.Value);
                        price = product.CurrentServicePriceEntity(car.CarModelId.Value);
                    }
                    else
                    {
                        price = product.CurrentPriceEntity;
                    }
                    orderItems.Add(new OrderItem
                    {
                        Product = product,
                        Price = price,
                        Quantity = 1,
                        TotalPrice = price.Amount
                    });
                    Session.Remove("cart");
                    Session.Add("cart", orderItems);
                }

            }
            if (carId.HasValue)
            {
                ViewData["carId"] = carId;
                ViewData["carRegistrationNumber"] = customerRepository.GetCar(carId.Value).RegistrationNumber;
            }
            return PartialView("_ShoppingCart", (IEnumerable<OrderItem>)Session["cart"]);
        }
Пример #3
0
 partial void DeletePrice(Price instance);
Пример #4
0
 partial void UpdatePrice(Price instance);
Пример #5
0
 partial void InsertPrice(Price instance);
Пример #6
0
		private void detach_Prices(Price entity)
		{
			this.SendPropertyChanging();
			entity.Product = null;
		}
Пример #7
0
		private void attach_Prices(Price entity)
		{
			this.SendPropertyChanging();
			entity.Product = this;
		}
Пример #8
0
		private void detach_Prices(Price entity)
		{
			this.SendPropertyChanging();
			entity.CarModel = null;
		}
Пример #9
0
		private void attach_Prices(Price entity)
		{
			this.SendPropertyChanging();
			entity.CarModel = this;
		}