예제 #1
0
        /// <summary>
        /// Deletes selected motherboard.
        /// </summary>
        /// <param name="obj"></param>
        private async void ExecDeleteMotherboardAsync(object obj)
        {
            Motherboard motherboard = (Motherboard)ProductListView.ProductListUserControl.MotherboardList.SelectedItem;

            Motherboards.Remove(motherboard);

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

            case ConnectionResource.LOCALMYSQL:
                using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL))
                {
                    ctx.DbSetMotherboards.Attach(motherboard);
                    ctx.DbSetMotherboards.Remove(motherboard);
                    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);
        }