Beispiel #1
0
        public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Genre,Price")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Id,name,author,dateCompleted")] Book book)
        {
            if (ModelState.IsValid)
            {
                book.Id = Guid.NewGuid();
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Genre,Price")] Book book)
        {
            if (ModelState.IsValid)
            {
                //Reservation res = new Reservation()
                //{
                //    ReservationDate = DateTime.Now,
                //    ReturnDate = DateTime.Now.AddDays(1),
                //    Title = "aaaaa"
                //};

                //_context.Add(res);
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
Beispiel #4
0
 public async Task Create(Book book)
 {
     _context.Add(book);
     await _context.SaveChangesAsync();
 }
        public async Task <IActionResult> New(int id, string bookGenre, int BookId, [Bind("Title,BookId,ReservationDate,ReturnDate")] Reservation reservation)
        {
            var resDate = from m in _context.Reservation
                          select m;
            var books = from m in _context.Book
                        select m;
            var bookQueryGenre = from m in _context.Book
                                 select m.Genre;

            {
                SelectList myGenres = new SelectList(await bookQueryGenre.Distinct().ToListAsync());

                reservation.BookGenres = myGenres;
                //var items = await books.Select(x => x).Where(x => x.Genre == bookGenre).ToListAsync();
                //var filterdItems = items.Where(s => s.Genre == bookGenre);
                //SelectList myTitle = new SelectList(items, "Id", "Title");
                if (bookGenre != "-2")
                {
                    SelectList myTitle = new SelectList(await books.Where(s => s.Genre == bookGenre).ToListAsync(), "Id", "Title");
                    reservation.BookNames = myTitle;
                }
                else
                {
                    SelectList myTitle = new SelectList(await books.ToListAsync(), "Id", "Title");
                    reservation.BookNames = myTitle;
                }
            }

            if (id != reservation.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    if (resDate.Any(m => m.BookId == reservation.BookId) && BookId != -1 && bookGenre != "-2")
                    {
                        if (!(reservation.ReservationDate > reservation.ReturnDate))
                        {
                            //   List<Element> _context.Reservation = BuildList();
                            bool i            = true;
                            var  bookQueryres = from m in _context.Reservation
                                                where m.BookId == BookId
                                                select m;
                            foreach (var item in bookQueryres)
                            {
                                if (((reservation.ReservationDate >= item.ReturnDate) && (reservation.ReturnDate > reservation.ReservationDate)) ||
                                    ((reservation.ReturnDate <= item.ReservationDate) && (reservation.ReturnDate > reservation.ReservationDate)))
                                {
                                }
                                else
                                {
                                    i = false;
                                    break;
                                }
                            }
                            if (i == true)
                            {
                                _context.Add(reservation);
                                await _context.SaveChangesAsync();

                                return(RedirectToAction(nameof(Index)));
                            }
                            else
                            {
                                ViewBag.ErrorMessage = "Reservation is not valid, please check !";
                            }
                        }
                        else
                        {
                            ViewBag.ErrorMessage = "Reservation is not valid, please check !";
                        }
                    }
                    else if (!(reservation.ReservationDate < reservation.ReturnDate))
                    {
                        ViewBag.ErrorMessage = "ReturnDate is not valid, please check !";
                    }
                    else if (BookId == -1 && bookGenre != "-2")
                    {
                        ViewBag.ErrorMessage = "Please don't forget to choose a book !";
                    }
                    else if (bookGenre == "-2")
                    {
                        ViewBag.ErrorMessage = "Please don't forget to choose a genre !";
                    }
                    else
                    {
                        _context.Add(reservation);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReservationExists(reservation.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //return RedirectToAction(nameof(Index));
            }
            return(View(reservation));
        }
Beispiel #6
0
 public async Task Create(Autor author)
 {
     _context.Add(author);
     await _context.SaveChangesAsync();
 }
Beispiel #7
0
 public async Task Create(Purchase purchase)
 {
     _context.Add(purchase);
     await _context.SaveChangesAsync();
 }
Beispiel #8
0
 public async Task Create(PurchasesHistory purchasehistory)
 {
     _context.Add(purchasehistory);
     await _context.SaveChangesAsync();
 }