public async Task <Order> AddOrderItem(Order order, OrderItemModel item, decimal valueTotalItem)
        {
            var products = new List <OrderSubItem>();

            foreach (var produID in item.Products)
            {
                OrderSubItem product = new OrderSubItem(order.OrderID, produID);
                products.Add(product);
            }

            OrderItem orderItem = new OrderItem(
                order.OrderID,
                item.OrderItemTypeID,
                item.Description,
                valueTotalItem,
                products
                );

            order.Items.Add(orderItem);

            await _uow.OrderItemRepository.Add(order.Items);

            return(order);
        }
Exemple #2
0
        /// <summary>
        ///  Function for saving data in orderitems and OrderSubItems table
        /// </summary>
        /// <param name="OrderMgntEntities"></param>
        /// <param name="Order_Id"></param>
        /// <param name="SelectedItemList"></param>
        /// <param name="ProductSubGroupId"></param>
        /// <returns></returns>
        private int SaveDatainOrderSubItem(OrderMgntEntities OrderMangtDB, int Order_Id, string SelectedItemList, int ProductSubGroupId)
        {
            int OrderItemRowID, OrderSubItemRowID;
            var EntityOrderItems = new OrderItem
            {
                Order_Id = Order_Id,
                Created = DateTime.Now,
            };
            // Add the OrderItems entity
            OrderMangtDB.OrderItems.Add(EntityOrderItems);
            // Update the entity in the database
            OrderMangtDB.SaveChanges();
            // Get the Row_Id generated by the database
            OrderItemRowID = EntityOrderItems.Row_Id;

            var EntityOrdersubItems = new OrderSubItem
            {
                OrderItemId = OrderItemRowID,
                ProductSubGroupId = ProductSubGroupId, // get "Rental Photography" value form the ProductSubGroups table
                OptionSelected = SelectedItemList.ToString(),
                Created = DateTime.Now,
            };

            // Add the OrderItems entity
            OrderMangtDB.OrderSubItems.Add(EntityOrdersubItems);
            // Update the entity in the database
            OrderMangtDB.SaveChanges();
            // Get the Row_Id generated by the database
            return OrderSubItemRowID = EntityOrderItems.Row_Id;
        }