예제 #1
0
        /// <summary>
        /// Deletes selected storage component.
        /// </summary>
        /// <param name="obj"></param>
        private async void ExecDeleteStorageAsync(object obj)
        {
            Storage storageComponent = (Storage)ProductListView.ProductListUserControl.StorageList.SelectedItem;

            StorageComponents.Remove(storageComponent);

            switch (App.DataSource)
            {
            case ConnectionResource.LOCALAPI:
                await new WebServiceManager <Storage>().DeleteAsync(storageComponent);
                break;

            case ConnectionResource.LOCALMYSQL:
                using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL))
                {
                    ctx.DbSetStorages.Attach(storageComponent);
                    ctx.DbSetStorages.Remove(storageComponent);
                    await ctx.SaveChangesAsync();
                }
                break;

            default:
                break;
            }
        }
        /// <summary>
        /// Adds the selected product to the cart's items.
        /// </summary>
        /// <param name="obj"></param>
        private void ExecAddToCart(object obj)
        {
            ProductListUserControl productListUC = CartView.CartUC.ProductsUC;
            CartItem cartItem = new CartItem();

            cartItem.Cart     = Cart;
            cartItem.Quantity = 1;

            if (productListUC.CPUList.SelectedIndex != -1) // CPU
            {
                CPU cpu = (CPU)productListUC.CPUList.SelectedItem;
                CPUs.Remove(cpu);
                cartItem.Product = cpu;
                cartItem.Price   = cpu.Price;
            }
            else if (productListUC.GPUList.SelectedIndex != -1) // GPU
            {
                GPU gpu = (GPU)productListUC.GPUList.SelectedItem;
                GPUs.Remove(gpu);
                cartItem.Product = gpu;
                cartItem.Price   = gpu.Price;
            }
            else if (productListUC.MotherboardList.SelectedIndex != -1) // Motherboard
            {
                Motherboard motherboard = (Motherboard)productListUC.MotherboardList.SelectedItem;
                Motherboards.Remove(motherboard);
                cartItem.Product = motherboard;
                cartItem.Price   = motherboard.Price;
            }
            else if (productListUC.MemoryList.SelectedIndex != -1) // Memory
            {
                Memory memory = (Memory)productListUC.MemoryList.SelectedItem;
                Rams.Remove(memory);
                cartItem.Product = memory;
                cartItem.Price   = memory.Price;
            }
            else if (productListUC.StorageList.SelectedIndex != -1) // Storage
            {
                Storage storage = (Storage)productListUC.StorageList.SelectedItem;
                StorageComponents.Remove(storage);
                cartItem.Product = storage;
                cartItem.Price   = storage.Price;
            }
            else if (productListUC.PSUList.SelectedIndex != -1) // PSU
            {
                PSU psu = (PSU)productListUC.PSUList.SelectedItem;
                PSUs.Remove(psu);
                cartItem.Product = psu;
                cartItem.Price   = psu.Price;
            }
            else // Case
            {
                Case pcCase = (Case)productListUC.CaseList.SelectedItem;
                Cases.Remove(pcCase);
                cartItem.Product = pcCase;
                cartItem.Price   = pcCase.Price;
            }

            cartItem.Product.Stock--;
            Cart.Total += cartItem.Price;
            Cart.Items.Add(cartItem);
        }