public async Task <IActionResult> PutGenre(int id, Genre genre) { if (id != genre.Id) { return(BadRequest()); } _context.Entry(genre).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GenreExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutPerson([FromRoute] long id, [FromBody] Person person) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != person.PersonId) { return(BadRequest()); } _context.Entry(person).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCompany(int id, Company company) { if (id != company.Id) { return(BadRequest()); } movieDBContext.Entry(company).State = EntityState.Modified; try { await movieDBContext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompanyExist(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IHttpActionResult> PutMovie(int id, Movie movie) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != movie.ID) { return(BadRequest()); } _context.Entry(movie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutUserMovieRating(int id, UserMovieRating userMovieRating) { if (id != userMovieRating.Id) { return(BadRequest()); } _context.Entry(userMovieRating).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserMovieRatingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutMovieActorCast(int id, MovieActorCast movieActorCast) { if (id != movieActorCast.Id) { return(BadRequest()); } movieDBContext.Entry(movieActorCast).State = EntityState.Modified; try { await movieDBContext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieActorCastExist(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutRoles([FromRoute] string id, [FromBody] Roles roles) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != roles.Id) { return(BadRequest()); } _context.Entry(roles).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RolesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutRelatedMovie(int id, RelatedMovie relatedMovie) { if (id != relatedMovie.RealtedMovieId) { return(BadRequest()); } _context.Entry(relatedMovie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RelatedMovieExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <T> AddAsync(T entity) { await _DBContext.Set <T>().AddAsync(entity); await _DBContext.SaveChangesAsync(); return(entity); }
public async Task <IActionResult> Update(int score, string id) { Movie movie = await _movieDB.Movies.FirstOrDefaultAsync(m => m.Id == id); movie.Rating = score; _movieDB.Update(movie); await _movieDB.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("CategoryId,CategoryName,CategoryCode")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("MovieID,Category,Title,Year,Director,Rating,Edited,LentTo,Notes")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Create([Bind("ID,Title,ReleaseDate,Genre,Price,Test")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,EmailId,pwd,retypwd")] RegisterModel registerModel) { if (ModelState.IsValid) { _context.Add(registerModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(registerModel)); }
public async Task <IActionResult> Create([Bind("MovieId,Name,Director,ReleaseDate,Email,Language")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <ActionResult> Create([Bind(Include = "GenreID,Type")] Genre genre) { if (ModelState.IsValid) { db.Genre.Add(genre); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(genre)); }
public async Task <IActionResult> Create([Bind("Id,Name,ReleaseDate,Director,Languages,EmailID,CategoryId")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", movie.CategoryId); return(View(movie)); }
public async Task <IActionResult> Create([Bind("Id,Title,Genre,Runtime")] Movies movies) { if (ModelState.IsValid) { _context.Add(movies); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag["Error"] = "An error has occurred in the program"; return(View("Index", ViewBag)); }
public async Task <ActionResult> Create([Bind(Include = "UserID,Name")] User user) { if (ModelState.IsValid) { db.Users.Add(user); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(user)); }
public async Task <IActionResult> Create([Bind("LangId,Language,MovieId")] LanguageModel languageModel) { if (ModelState.IsValid) { _context.Add(languageModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MovieId"] = new SelectList(_context.MovieModels, "MovieID", "MovieDescription", languageModel.MovieId); return(View(languageModel)); }
public async Task <ActionResult> Create([Bind(Include = "ID,Name,Genra,Price,Date")] Movie movie) { if (ModelState.IsValid) { db.Movies.Add(movie); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(movie)); }
public async Task <ActionResult> Create([Bind(Include = "ID,FilmTypeID,Name,Director,Description")] Film film) { if (ModelState.IsValid) { db.Films.Add(film); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.FilmTypeID = new SelectList(db.FilmTypes, "ID", "Name", film.FilmTypeID); return(View(film)); }
public async Task <ActionResult> Create([Bind(Include = "ID,FilmID,TicketTypeID,Price,Quantity,StartHours,EndHours")] Ticket ticket) { if (ModelState.IsValid) { db.Tickets.Add(ticket); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.FilmID = new SelectList(db.Films, "ID", "Name", ticket.FilmID); ViewBag.TicketTypeID = new SelectList(db.TicketTypes, "ID", "Name", ticket.TicketTypeID); return(View(ticket)); }
protected async Task <UserReview> AddReview(MovieReviewRequest request) { UserReview newReview = new UserReview() { UserId = request.UserId, MovieId = request.MovieId, Rating = request.Rating }; await _dbContext.UserReviews.AddAsync(newReview); await _dbContext.SaveChangesAsync(); return(newReview); }
public async Task <ActionResult> Create([Bind(Include = "MovieID,Name,Info,GenreID,Year")] Movie movie) { if (ModelState.IsValid) { db.Movies.Add(movie); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } var genres = await db.Genre.ToListAsync(); ViewBag.Genres = genres; return(View(movie)); }
public async Task <IActionResult> PostAsync([FromBody] int movieId, [FromRoute] int userId) { var fav = new Favourites(); fav.MovieId = movieId; fav.UserId = userId; await _context.Favourites.AddAsync(fav); int rows = await _context.SaveChangesAsync(); if (rows == 0) { return(BadRequest("item not added")); } return(StatusCode(201)); }
public async Task <Movie> RateMovieAsync(int movieId, int userId, int rating, CancellationToken cancellationToken) { // ensure movie exists if (!await dbContext.Movies.AnyAsync(m => m.Id == movieId, cancellationToken)) { return(null); } // rate movie var movieRating = await dbContext.MovieRatings.FirstOrDefaultAsync(mr => mr.UserId == userId && mr.MovieId == movieId, cancellationToken); if (movieRating == null) { await dbContext.MovieRatings.AddAsync( new MovieRatings { UserId = userId, MovieId = movieId, Rating = rating }, cancellationToken); } else { movieRating.Rating = rating; } await dbContext.SaveChangesAsync(cancellationToken); // returns rated movie return(await dbContext.Movies .FirstOrDefaultAsync(m => m.Id == movieId, cancellationToken)); }
public async Task <ActionResult> Create([Bind(Include = "RentID,UserID,MovieID,From,To")] Rent rent) { DateTime today = DateTime.Today; bool isActiveRent = await db.Rents.AnyAsync(r => r.To > DateTime.Now); //This block is responsible for checking whether a User has an active rent also it's putting a restriction to make a rent for other user //in case that movie is still in usage if (isActiveRent) { return(ActionResult()); } //This block is responsible for not letting make a rent in the past if (rent.From < today || rent.To < today) { return(ActionResult()); } //This block is responsible for checking a "To" date is not less than "From" date if (rent.To < rent.From) { return(ActionResult()); } if (ModelState.IsValid) { db.Rents.Add(rent); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } var users = await db.Users.ToListAsync(); ViewBag.Users = users; var movies = await db.Movies.ToListAsync(); ViewBag.Movies = movies; return(View(rent)); }
public async Task <IActionResult> PostComment(string commentText, string id) { Comment userComment = new Comment { MovieImdbApi = id, Text = commentText, UserId = _userManager.GetUserId(User) }; _moviedb.Add(userComment); await _moviedb.SaveChangesAsync(); return(RedirectToAction("Index", "Info", new { id })); }
public async Task <IActionResult> PostAsync(UserDetails item) { context.UserDetails.Add(item); var rows = await context.SaveChangesAsync(); if (rows == 0) { return(BadRequest("Cannot add User")); } return(StatusCode(201)); }