private void InitializeViewData()
        {
            OrderViewData.btncommand      = "";
            OrderViewData.Products        = new List <Product>();
            OrderViewData.CalculatedPrice = 0;

            Product p = new Product();

            p.ProductId           = 1;
            p.ProductName         = "NewProduct";
            p.IsActive            = true;
            p.SelectedMaterialId  = 0;
            p.IncludeProductPrice = false;
            OrderViewData.Products.Add(p);
            OrderViewData.ActiveProductIndex = 0;
            OrderViewData.Materials          = OrderDemoDataBase.GetMaterials();
            OrderViewData.Orders             = OrderDemoDataBase.GetOrders();
        }
        public ActionResult Index(Order order)
        {
            switch (OrderViewData.btncommand)
            {
            case "SAVE":
            {
                OrderDemoDataBase.AddOrderToDataBase(order);

                InitializeViewData();
                order = ClearOrderModel(order);

                return(View("Index", order));
            }

            case "SEND":
            {
                return(View("OrderValidationSuccess", order));
            }

            case "GETORDER":
            {
                foreach (Order o in OrderViewData.Orders)
                {
                    if (o.OrderId == OrderViewData.RequestedOrder)
                    {
                        //GetAllProductsforOrderId
                        //SetOrderViewDataValues
                        o.RequestedOrderId               = OrderViewData.RequestedOrder;
                        OrderViewData.Products           = new List <Product>();
                        OrderViewData.Products           = OrderDemoDataBase.GetProducts(o.OrderId);
                        OrderViewData.ActiveProductIndex = 0;
                        o.ProductId                        = OrderViewData.Products[0].ProductId;
                        o.ProductName                      = OrderViewData.Products[0].ProductName;
                        o.ProductPrice                     = OrderViewData.Products[0].ProductPrice;
                        o.IncludeProductPrice              = OrderViewData.Products[0].IncludeProductPrice;
                        o.MaterialId                       = OrderViewData.Products[0].SelectedMaterialId;
                        OrderViewData.CalculatedPrice      = (int)o.TotalPrice;
                        OrderViewData.Products[0].IsActive = true;
                        return(View("Index", o));
                    }
                }
                return(View("Index", order));
            }

            case "NEWORDER":
            {
                InitializeViewData();
                order = ClearOrderModel(order);
                return(View("Index", order));
            }

            case "UPDATEORDER":
            {
                OrderDemoDataBase.UpdateOrderInDataBase(order);
                OrderViewData.Products = OrderDemoDataBase.GetProducts(order.OrderId);

                OrderViewData.Orders = OrderDemoDataBase.GetOrders();
                int i = 0;
                foreach (Order o in OrderViewData.Orders)
                {
                    if (o.OrderId == OrderViewData.RequestedOrder)
                    {
                        o.OrderName        = OrderViewData.Orders[i].OrderName;
                        o.DeliveryDate     = OrderViewData.Orders[i].DeliveryDate;
                        o.ValidUntil       = OrderViewData.Orders[i].ValidUntil;
                        o.TotalPrice       = OrderViewData.Orders[i].TotalPrice;
                        o.RequestedOrderId = OrderViewData.RequestedOrder;

                        OrderViewData.Products           = new List <Product>();
                        OrderViewData.Products           = OrderDemoDataBase.GetProducts(o.OrderId);
                        OrderViewData.ActiveProductIndex = 0;
                        o.ProductId                        = OrderViewData.Products[0].ProductId;
                        o.ProductName                      = OrderViewData.Products[0].ProductName;
                        o.ProductPrice                     = OrderViewData.Products[0].ProductPrice;
                        o.IncludeProductPrice              = OrderViewData.Products[0].IncludeProductPrice;
                        o.MaterialId                       = OrderViewData.Products[0].SelectedMaterialId;
                        OrderViewData.CalculatedPrice      = (int)o.TotalPrice;
                        OrderViewData.Products[0].IsActive = true;
                        return(View("Index", o));
                    }
                    i++;
                }


                return(View("Index", order));
            }
            }
            return(View("Index", order));
        }