public async Task <IActionResult> Create([Bind("IdImprumut,IdCarte,IdClient,DataImprumut,DataReturnare")] ImprumuturiCarti imprumuturiCarti)
        {
            if (ModelState.IsValid)
            {
                _context.Add(imprumuturiCarti);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewBag.IdClient       = new SelectList(_context.Clienti, "IdClient", "Nume", imprumuturiCarti.IdClient);
            imprumuturiCarti.Carti = _context.Carti.Find(imprumuturiCarti.IdCarte);
            return(View(imprumuturiCarti));
        }
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(BadRequest());
            }
            ImprumuturiCarti imprumut = _context.ImprumuturiCarti
                                        .Include(b => b.Carti)
                                        .Include(c => c.Clienti)
                                        .Where(b => b.IdCarte == id && b.DataReturnare == null)
                                        .FirstOrDefault();

            if (imprumut == null)
            {
                return(NotFound());
            }
            return(View(imprumut));
        }
        public async Task <IActionResult> Edit([Bind("IdImprumut,IdCarte,IdClient,DataImprumut,DataReturnare")] ImprumuturiCarti imprumuturiCarti)
        {
            if (ModelState.IsValid)
            {
                var borrowHistoryItem = _context.ImprumuturiCarti.Include(i => i.Carti)
                                        .FirstOrDefault(i => i.IdImprumut == imprumuturiCarti.IdImprumut);
                if (borrowHistoryItem == null)
                {
                    return(BadRequest());
                }

                borrowHistoryItem.DataReturnare = DateTime.Now;
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Carti"));
            }
            return(View(imprumuturiCarti));
        }
        public IActionResult Create(int?id)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            var book = _context.Carti.Find(id);

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

            var imprumut = new ImprumuturiCarti {
                IdCarte = book.IdCarte, DataImprumut = DateTime.Now, Carti = book
            };

            ViewBag.IdClient = new SelectList(_context.Clienti, "IdClient", "Nume");
            return(View(imprumut));
        }