public async Task <IActionResult> Edit(int id, [Bind("Id,OrderId,ComputerId")] ComputerOrder computerOrder)
        {
            if (id != computerOrder.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(computerOrder);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ComputerOrderExists(computerOrder.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ComputerId"] = new SelectList(_context.Computer, "Id", "Name", computerOrder.ComputerId);
            ViewData["OrderId"]    = new SelectList(_context.Order, "Id", "Id", computerOrder.OrderId);
            return(View(computerOrder));
        }
        //Inserta un elemento ComputerOrder nuevo en la bd ComputerOrder y devuelve el id de este elemento
        public async Task <int> InsertComputerOrderToDBAsync(int orderId, int computerId)
        {
            ComputerOrder computerOrder = new ComputerOrder();

            computerOrder.OrderId    = orderId;
            computerOrder.ComputerId = computerId;
            _context.Add(computerOrder);
            await _context.SaveChangesAsync();

            return(computerOrder.Id);
        }
        public async Task <IActionResult> Create([Bind("Id,OrderId,ComputerId")] ComputerOrder computerOrder)
        {
            if (ModelState.IsValid)
            {
                _context.Add(computerOrder);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ComputerId"] = new SelectList(_context.Computer, "Id", "Name", computerOrder.ComputerId);
            ViewData["OrderId"]    = new SelectList(_context.Order, "Id", "Id", computerOrder.OrderId);
            return(View(computerOrder));
        }
Example #4
0
        public MainWindow()
        {
            InitializeComponent();

            // Initializing object so that I can gather the data from the class fields to populate the base form
            ComputerOrder co = new ComputerOrder();

            // Setting local arrays to keep the names of the fields from the ComputerOrder class
            string[] driveItems  = co.DriveInfo;
            string[] moboItems   = co.MoboInfo;
            string[] memItems    = co.MemoryInfo;
            string[] periphItems = co.PeripheralsInfo;

            // Setting drive radio buttons
            radDrive1.Content = driveItems[0];
            radDrive2.Content = driveItems[1];
            radDrive3.Content = driveItems[2];

            // Setting mobo collection list for the combobox
            cbxMobo.ItemsSource = moboItems;

            // Setting memory radio buttons
            radMem1.Content = memItems[0];
            radMem2.Content = memItems[1];
            radMem3.Content = memItems[2];

            // Setting up peripheral checkboxes
            cbPeriph1.Content = periphItems[0];
            cbPeriph2.Content = periphItems[1];
            cbPeriph3.Content = periphItems[2];
            cbPeriph4.Content = periphItems[3];
            cbPeriph5.Content = periphItems[4];
            cbPeriph6.Content = periphItems[5];
            cbPeriph7.Content = periphItems[6];
            cbPeriph8.Content = periphItems[7];
        }
Example #5
0
        private void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            // Instantiating a new object
            ComputerOrder comp = new ComputerOrder();

            // Groupbox selection for motherboards
            if (cbxMobo.SelectedIndex == 0)
            {
                comp.MoboOptionIndex = 0;
            }
            if (cbxMobo.SelectedIndex == 1)
            {
                comp.MoboOptionIndex = 1;
            }
            if (cbxMobo.SelectedIndex == 2)
            {
                comp.MoboOptionIndex = 2;
            }

            // Drive index
            if (radDrive1.IsChecked == true)
            {
                comp.DriveOptionIndex = 0;
            }
            if (radDrive2.IsChecked == true)
            {
                comp.DriveOptionIndex = 1;
            }
            if (radDrive3.IsChecked == true)
            {
                comp.DriveOptionIndex = 2;
            }

            // Memory Index
            if (radMem1.IsChecked == true)
            {
                comp.MemoryOptionIndex = 0;
            }
            if (radMem2.IsChecked == true)
            {
                comp.MemoryOptionIndex = 1;
            }
            if (radMem3.IsChecked == true)
            {
                comp.MemoryOptionIndex = 2;
            }

            // Creating new list for peripherals
            List <int> tempPeriphList = new List <int>();

            if (cbPeriph1.IsChecked == true)
            {
                tempPeriphList.Add(0);
            }
            if (cbPeriph2.IsChecked == true)
            {
                tempPeriphList.Add(1);
            }
            if (cbPeriph3.IsChecked == true)
            {
                tempPeriphList.Add(2);
            }
            if (cbPeriph4.IsChecked == true)
            {
                tempPeriphList.Add(3);
            }
            if (cbPeriph5.IsChecked == true)
            {
                tempPeriphList.Add(4);
            }
            if (cbPeriph6.IsChecked == true)
            {
                tempPeriphList.Add(5);
            }
            if (cbPeriph7.IsChecked == true)
            {
                tempPeriphList.Add(6);
            }
            if (cbPeriph8.IsChecked == true)
            {
                tempPeriphList.Add(7);
            }

            // Setting the temporary list object into the class' peripheral list object
            comp.PeriphList = tempPeriphList;

            // Displaying to user
            txbResults.Text = comp.OrderSummary;
        }