Exemplo n.º 1
0
        public async Task Delete(int id)
        {
            var purchasehistory = await _context.PurchasesHistory.FindAsync(id);

            _context.PurchasesHistory.Remove(purchasehistory);
            await _context.SaveChangesAsync();
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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));
        }
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var bookMvcBookUser = from m in _context.BookMvcBookUser
                                  where m.BookId == id
                                  where m.MvcBookUserId == User.FindFirstValue(ClaimTypes.NameIdentifier)
                                  select m;



            /*  var book = await _context.Book.FindAsync(id);*/
            _context.BookMvcBookUser.RemoveRange(bookMvcBookUser);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 6
0
        public async Task Update(Book book)
        {
            _context.Update(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));
        }
Exemplo n.º 8
0
 public async Task Create(Autor author)
 {
     _context.Add(author);
     await _context.SaveChangesAsync();
 }
Exemplo n.º 9
0
 public async Task Delete(int id)
 {
     var purchase = await _context.Purchases.FindAsync(id);
     _context.Purchases.Remove(purchase);
     await _context.SaveChangesAsync();
 }