示例#1
0
        public async Task <IActionResult> Create([Bind("RentedMovieId,CusId,TvShowId,RentalDate,ReturnDate")] RentedMovie rentedMovie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rentedMovie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CusId"]    = new SelectList(_context.Customers, "CustomersId", "FirstName", rentedMovie.CusId);
            ViewData["TvShowId"] = new SelectList(_context.TvShow, "TvId", "Title", rentedMovie.TvShowId);
            return(View(rentedMovie));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("RentedMovieId,UsersID,TvShowID,RentDate,ReturnDate")] RentedMovies rentedMovies)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rentedMovies);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UsersID"]  = new SelectList(_context.Users, "UsersID", "Name", rentedMovies.UsersID);
            ViewData["TvShowID"] = new SelectList(_context.TvShow, "TvShowID", "ImageUrl", rentedMovies.TvID);
            return(View(rentedMovies));
        }
示例#3
0
        public async Task <IActionResult> AddReview(int id, AddReviewRequest request)
        {
            var review = new Review
            {
                UserId = request.UserId,
                BookId = id,
                Text   = request.Text
            };

            _context.Add(review);
            await _context.SaveChangesAsync();

            return(Accepted());
        }
        public async Task <IActionResult> Create([Bind("Id,Title,Genre,Rating,ImdbUrl,ImageUrl,ImageFile")] TvShow tvShow)
        {
            if (ModelState.IsValid)
            {
                if (tvShow.ImageFile != null)
                {
                    await UploadFile(tvShow);
                }

                _context.Add(tvShow);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tvShow));
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("Date,Profit,Investments")] ARR tvShow)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tvShow);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tvShow));
        }
示例#6
0
        public async Task <ActionResult <User> > Register(RegisterRequest request)
        {
            var existing = await _context.Users.FirstOrDefaultAsync(x => x.Email == request.Email);

            if (existing != null)
            {
                return(BadRequest("User with the same email already exists"));
            }

            var user = new User
            {
                Name     = request.Name,
                Email    = request.Email,
                Password = request.Password
            };

            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            return(user);
        }
示例#7
0
        public async Task <IActionResult> Create([Bind("Img,Name,Author,Year,Price,DownloadLink,Text")] CreateBookRequest request)
        {
            if (ModelState.IsValid)
            {
                var book = new Book
                {
                    Img          = request.Img,
                    Name         = request.Name,
                    Author       = request.Author,
                    Year         = request.Year,
                    Price        = request.Price,
                    DownloadLink = request.DownloadLink,
                    Text         = request.Text
                };

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

                return(RedirectToAction(nameof(BookIndex)));
            }

            return(View("Error"));
        }
示例#8
0
 public async Task SaveCangesAsync()
 {
     await dbContext.SaveChangesAsync();
 }