Esempio n. 1
0
 public int InitiateOrder(int? carId, DateTime orderDate, DateTime appointmentDate, List<OrderItem> orderItems)
 {
     Order newOrder = new Order
     {
         CarId = carId,
         OrderDate = orderDate,
         AppointmentDate = appointmentDate,
     };
     foreach (var orderItem in orderItems)
     {
         OrderItem newOrderItem = new OrderItem
         {
             ProductId = orderItem.ProductId,
             Quantity = orderItem.Quantity,
             PriceId = orderItem.PriceId,
             TotalPrice = orderItem.Price.Amount * orderItem.Quantity
         };
         if (orderItem.Product.IsService)
         {
             foreach(var productComponent in orderItem.Product.ProductComponents)
             {
                 List<TempComponentStockQuantity> tempComponentStocks = stockRepository.SubtractComponentStock(productComponent.ComponentId, orderItem.Quantity);
                 foreach (var tempComponentStock in tempComponentStocks)
                 {
                     newOrderItem.OrderItemsStocks.Add(new OrderItemsStock
                     {
                         ComponentStockId = tempComponentStock.ComponentStockId,
                         Quantity = tempComponentStock.Quantity
                     });
                 }
             }
         }
         else
         {
             List<TempProductStockQuantity> tempProductStocks = stockRepository.SubtractProductStock(newOrderItem.ProductId, newOrderItem.Quantity);
             foreach (var tempProductStock in tempProductStocks)
             {
                 newOrderItem.OrderItemsStocks.Add(new OrderItemsStock
                 {
                     ProductStockId = tempProductStock.ProductStockId,
                     Quantity = tempProductStock.Quantity
                 });
             }
         }
         newOrder.OrderItems.Add(newOrderItem);
     }
     db.Orders.InsertOnSubmit(newOrder);
     Save();
     return newOrder.Id;
 }
 partial void DeleteOrder(Order instance);
 partial void UpdateOrder(Order instance);
 partial void InsertOrder(Order instance);
		private void detach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.Employee = null;
		}
		private void attach_Orders(Order entity)
		{
			this.SendPropertyChanging();
			entity.Employee = this;
		}