public async Task <IActionResult> AddOrEdit(int id, [Bind("Title,ReleaseDate,Genre,Price")] Movie movie) { if (ModelState.IsValid) { //Insert if (id == 0) { _context.Add(movie); await _context.SaveChangesAsync(); } //Update else { try { _context.Update(movie); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieModelExists(movie.Id)) { return(NotFound()); } else { throw; } } } return(Json(new { isValid = true, html = await Helper.RenderRazorViewToStringAsync(this, "_ViewAll", _context.Movies.ToList()) })); } return(Json(new { isValid = false, html = await Helper.RenderRazorViewToStringAsync(this, "AddOrEdit", movie) })); }
public async Task <Movie> Create(Movie movie) { _db.Movies.Add(movie); await _db.SaveChangesAsync(); return(movie); }
public async Task <Movie> Create(Movie model) { db.Movies.Add(model); await db.SaveChangesAsync(); return(model); }
public async Task <IActionResult> PutMovie(int id, Movie movie) { 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(NoContent()); }
public async Task <IActionResult> PutActor(int id, Actor actor) { if (id != actor.ActorId) { return(BadRequest()); } _context.Entry(actor).State = EntityState.Modified; var actors = new List <MovieActors>(); actors.AddRange(actor.MovieActors); var tablema = _context.MovieActors.Where(x => x.ActorId == actor.ActorId).ToList(); _context.MovieActors.RemoveRange(tablema); _context.MovieActors.AddRange(actors); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ActorExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <T> Add(T model) { await context.AddAsync <T>(model); await context.SaveChangesAsync(); return(model); }
public async Task <IActionResult> Create([Bind("Id,Name")] Rate rate) { if (ModelState.IsValid) { _context.Add(rate); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(rate)); }
public async Task <IActionResult> Create([Bind("ActorId,ActorFirstName,ActorLastName,ActorGender")] Actor actor) { if (ModelState.IsValid) { _context.Add(actor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(actor)); }
public async Task <IActionResult> Create([Bind("MovieId,Category,Title,Year,Director,Rating,Edited,Lent_to,Notes")] MovieInfo movieInfo) { if (ModelState.IsValid) { _context.Add(movieInfo); await _context.SaveChangesAsync(); return(RedirectToAction("Collection", movieInfo)); } return(View()); }
public async Task <IActionResult> Create([Bind("MovieId,Category,Title,YearReleased,DirectorName,MovieRating,IsEdited,IsLentTo,Notes")] AddMovie addMovie) { if (ModelState.IsValid) { _context.Add(addMovie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(addMovie)); }
public async Task <IActionResult> Create([Bind("MovieId,MovieTitle,MovieYear,MovieLanguage,MoviePath,MovieCoverImage")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Create([Bind("MovieID,Category,Title,Year,Director,Rating,Edited,LentTo,Notes")] MovieResponse movieResponse) { if (ModelState.IsValid) { _context.Add(movieResponse); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(movieResponse)); }
public async Task <IActionResult> Create([Bind("Id,Title,Genre,Rating,ImdbUrl")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Create([Bind("DirectorId,FirtsName,LastName,Email")] Director director) { if (ModelState.IsValid) { _context.Add(director); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(director)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Gender,DateOfBirth,DateOfDeath")] Persons persons) { if (ModelState.IsValid) { _context.Add(persons); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(persons)); }
public async Task <IActionResult> Create([Bind("Id,Firstname,Lastname,BirthOfDate")] Author author) { if (ModelState.IsValid) { _context.Add(author); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(author)); }
public async Task <IActionResult> Create(MovieCreateViewModel movie) { if (!TryValidateModel(movie)) { return(View(movie)); } string userId = User.FindFirstValue(ClaimTypes.NameIdentifier); Movie newMovie = new Movie() { Title = movie.Title, Description = movie.Description, ReleaseDate = movie.ReleaseDate, Genre = movie.Genre, WatchStatusId = movie.SelectedWatchStatus, MovieAppUserId = userId // MovieTag = movie.SelectedTags.Select(tag => new MovieTag() { TagId = tag }).ToList() }; var movieTags = new List <MovieTag>(); foreach (var selectedTag in movie.SelectedTags) { movieTags.Add(new MovieTag() { TagId = selectedTag }); } newMovie.MovieTags = movieTags; if (movie.Photo != null) { var uniqueFileName = Guid.NewGuid().ToString() + Path.GetExtension(movie.Photo.FileName); var pathName = Path.Combine(_hostingEnvironment.WebRootPath, "pics"); var fileNameWithPath = Path.Combine(pathName, uniqueFileName); using (var stream = new FileStream(fileNameWithPath, FileMode.Create)) { movie.Photo.CopyTo(stream); } newMovie.Photo = "/pics/" + uniqueFileName; } _movieDbContext.Movies.Add(newMovie); await _movieDbContext.SaveChangesAsync(); _messageService.Send("Er heeft iemand een film aangemaakt!"); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("RatingId,MovieRatings,MovieId")] RatingModel ratingModel) { if (ModelState.IsValid) { _context.Add(ratingModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MovieId"] = new SelectList(_context.MovieModels, "MovieId", "MovieName", ratingModel.MovieId); return(View(ratingModel)); }
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 = "Id,Title,ReleaseDate,Genre,Price,Rating")] Movie movie) { if (ModelState.IsValid) { db.Movies.Add(movie); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(movie)); }
public async Task <IActionResult> Create( [Bind("ID,Title,ReleaseDate,Genre,Price, Rating")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(movie)); }
public async Task <IActionResult> Create([Bind("Id,Title,Genre,Price,ReleaseDate,Rating")] Movie movie) { Log.Information("Added new Movie : " + movie.Title); if (ModelState.IsValid) //arayüzdeki uyarıları ve attirubute lerin çalışmasını sağlayan kısım { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Create([Bind("MovieId,Category,Title,Year,Director,Rating,Edited,LentTo,Notes")] ApplicationResponse applicationResponse) { if (ModelState.IsValid) { Context.Add(applicationResponse); //When in an async method use the savechangesAsync await Context.SaveChangesAsync(); //Takes us back to the index page return(RedirectToAction(nameof(Index))); } return(View(applicationResponse)); }
public async Task <IActionResult> Create([Bind("DirectorId,MovieId")] MovieDirection movieDirection) { if (ModelState.IsValid) { _context.Add(movieDirection); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DirectorId"] = new SelectList(_context.Directors, "DirectorId", "DirectorId", movieDirection.DirectorId); ViewData["MovieId"] = new SelectList(_context.Movies, "MovieId", "MovieId", movieDirection.MovieId); return(View(movieDirection)); }
public async Task <IActionResult> Create([Bind("Id,Title,Year,Description,GenreId,AuthorId")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AuthorId"] = new SelectList(_context.Authors, "Id", "Firstname", movie.AuthorId); ViewData["GenreId"] = new SelectList(_context.Genres, "Id", "Name", movie.GenreId); return(View(movie)); }
public async Task <IActionResult> Create([Bind("MovieId,GenreId")] MovieGenre movieGenre) { if (ModelState.IsValid) { _context.Add(movieGenre); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["GenreId"] = new SelectList(_context.Genres, "GenreId", "GenreId", movieGenre.GenreId); ViewData["MovieId"] = new SelectList(_context.Movies, "MovieId", "MovieId", movieGenre.MovieId); return(View(movieGenre)); }
public async Task <IActionResult> Create([Bind("Id,Title,Released,RunTime,Plot,FormatId,RateId")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FormatId"] = new SelectList(_context.Format, "Id", "Name", movie.FormatId); ViewData["RateId"] = new SelectList(_context.Rate, "Id", "Name", movie.RateId); return(View(movie)); }
public async Task <Actor> CreateActorAsync(string name, DateTime born) { var actor = new Actor() { Name = name, Born = born }; _dbContext.Add(actor); await _dbContext.SaveChangesAsync(); return(actor); }
public async Task <Studio> CreateStudio(StudioToPost studioToPost) { var addStudio = new Studio { Name = studioToPost.Name, City = studioToPost.City, State = studioToPost.State }; _context.Studios.Add(addStudio); await _context.SaveChangesAsync(); return(addStudio); }
public async Task <Principal> Create(Principal model) { try { db.Principals.Add(model); await db.SaveChangesAsync(); } catch (PostgresException pe) { logger.LogError($"[!!!{nameof(Create)}!!!] {pe.Message}"); return(null); } return(model); }