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;
 }
Exemple #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"]);
        }
 partial void DeletePrice(Price instance);
 partial void UpdatePrice(Price instance);
 partial void InsertPrice(Price instance);
		private void detach_Prices(Price entity)
		{
			this.SendPropertyChanging();
			entity.Product = null;
		}
		private void attach_Prices(Price entity)
		{
			this.SendPropertyChanging();
			entity.Product = this;
		}
		private void detach_Prices(Price entity)
		{
			this.SendPropertyChanging();
			entity.CarModel = null;
		}
		private void attach_Prices(Price entity)
		{
			this.SendPropertyChanging();
			entity.CarModel = this;
		}