Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("RentalID,UserID,BookID,RentalEndDate,ToPay")] Rental rental)
        {
            if (id != rental.RentalID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(rental);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RentalExists(rental.RentalID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookID"] = new SelectList(_context.Books, "BookID", "Author", rental.BookID);

            return(View(rental));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("BookID,Title,Author,Category")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
Ejemplo n.º 3
0
        // GET: Rentals
        public async Task <IActionResult> Index()
        {
            foreach (var item in _context.Rentals.ToList())
            {
                if (DateTime.Now > item.RentalEndDate)
                {
                    int x = (DateTime.Now - item.RentalEndDate).Days;
                    item.ToPay = Convert.ToDecimal(x) * 0.1m;
                }
            }
            await _context.SaveChangesAsync();

            var library_identityContext = _context.Rentals.Include(r => r.Book).Include(r => r.User);

            return(View(await library_identityContext.Where(d => d.UserID == User.GetId <string>()).ToListAsync()));
        }