示例#1
0
        public async Task <IActionResult> PutConsoleRentalConsole(int id, ConsoleRental consoleRental)
        {
            if (id != consoleRental.Id)
            {
                return(BadRequest());
            }

            _context.Entry(consoleRental).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ConsoleRentalConsoleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#2
0
        public async Task <ActionResult <ConsoleRental> > PostConsoleRentalConsole(ConsoleRental consoleRental)
        {
            _context.ConsoleRentals.Add(consoleRental);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetConsoleRental", new { id = consoleRental.Id }, consoleRental));
        }
示例#3
0
        public async Task <ActionResult <ConsoleRental> > GetConsoleRentalConsole(int id)
        {
            // var consoleRental = await _context.ConsoleRentals.FindAsync(id);
            // ConsoleRental consoleRentalFind = await _context.ConsoleRentals.FindAsync(id);
            ConsoleRental consoleRentalJoin = await _context.ConsoleRentals
                                              .Join(
                _context.Consoles,
                consoleRental => consoleRental.Console.Id,
                console => console.Id,
                (consoleRental, console) => new ConsoleRental {
                Id           = consoleRental.Id,
                StartDate    = consoleRental.StartDate,
                EndDate      = consoleRental.EndDate,
                CustomerName = consoleRental.CustomerName,
                Console      = console
            }).FirstOrDefaultAsync(i => i.Id == id);

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

            return(consoleRentalJoin);
        }