Пример #1
0
        public async Task <IActionResult> Create([Bind("RentedBookID,StudentID,BookID,RentDate,ReturnDate")] RentedBook rentedBook)
        {
            Book book = _context.Books.Find(rentedBook.BookID);

            var checkBook = _context.RentedBooks
                            .Include(r => r.Book)
                            .Include(r => r.Student).ToList();

            // if there are more than 1, book will be issued
            if (book.AvailableQuantity >= 1)
            {
                book.AvailableQuantity    -= 1;
                _context.Entry(book).State = EntityState.Modified;

                if (ModelState.IsValid)
                {
                    _context.Add(rentedBook);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            // if none, give a message telling user that the book is current unavailable
            else
            {
                ModelState.AddModelError(string.Empty,
                                         "The book is unavailable! It is rented by other students.");
            }

            ViewData["BookID"]    = new SelectList(_context.Books, "BookID", "BookID", rentedBook.BookID);
            ViewData["StudentID"] = new SelectList(_context.Students, "StudentID", "StudentID", rentedBook.StudentID);
            return(View(rentedBook));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Id,Name")] ResourceList resourceList)
        {
            if (ModelState.IsValid)
            {
                _context.Add(resourceList);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(resourceList));
        }
        public async Task <IActionResult> Create([Bind("Id,TagValue")] TopicTag topicTag)
        {
            if (ModelState.IsValid)
            {
                _context.Add(topicTag);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(topicTag));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Phase,ReleaseDate")] CinematicItem cinematicItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cinematicItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cinematicItem));
        }
Пример #5
0
        public async Task <IActionResult> Create([Bind("Id,FeedUrl,LearningResourceId")] ContentFeed contentFeed)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contentFeed);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LearningResourceId"] = new SelectList(_context.LearningResources, "Id", "Id", contentFeed.LearningResourceId);
            return(View(contentFeed));
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("RentedBookID,StudentID,BookID,RentDate,ReturnDate")] RentedBook rentedBook)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rentedBook);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookID"]    = new SelectList(_context.Books, "BookID", "BookID", rentedBook.BookID);
            ViewData["StudentID"] = new SelectList(_context.Students, "StudentID", "StudentID", rentedBook.StudentID);
            return(View(rentedBook));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("BookName,Author,Edition,ISBN,Subject,PublicDate,Format,NumofPages,AvailableQuantity")] Book book)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(book);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                ModelState.AddModelError("", "Unable to save changes. " + "Please check if there are any errors with the database");
            }

            return(View(book));
        }
Пример #8
0
        public async Task <IActionResult> Create([Bind("StudentFirstName,StudentLastName,StudentEmail,StudentPhoneNumber")] Student student)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(student);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(student));
        }
Пример #9
0
 public void Create(T entity)
 {
     _context.Add(entity);
     Save();
 }