Ejemplo n.º 1
0
        public async Task <IActionResult> Test(int?id, bool selectedCourse)
        {
            var viewModel = new RentalInventoryData();

            viewModel.Inventory = from i in _context.Inventory
                                  .Include(i => i.Rental)
                                  .Include(i => i.Location)
                                  where i.RentalID == null
                                  select i;

            var rental = await _context.Rental
                         .Include(r => r.User)
                         .AsNoTracking()
                         .SingleOrDefaultAsync(m => m.RentalID == id);

            if (id == null)
            {
                return(NotFound());
            }

            ViewData["RentalName"]     = rental.RentalName;
            ViewData["RentalReturn"]   = rental.RentalReturnDate;
            ViewData["RentalCheckout"] = rental.RentalCheckoutDate;
            ViewData["RentalNotes"]    = rental.RentalNotes;
            var rentalID = rental.RentalID;

            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> TestPost(int?id, bool selectedCourse)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var viewModel = new RentalInventoryData();

            viewModel.Inventory = from i in _context.Inventory
                                  .Include(i => i.Rental)
                                  .Include(i => i.Location)
                                  where i.RentalID == null
                                  select i;

            foreach (var x in viewModel.Inventory)
            {
                if (selectedCourse == true)
                {
                    _context.Database.ExecuteSqlCommand("UPDATE Inventory SET RentalID={0} WHERE InventoryID={1}", id, x.InventoryID);
                }
            }
            return(RedirectToAction("Details/" + id));
        }