public async Task <IActionResult> AddOrEdit(int id, [Bind("MovieID,TmdbID,Title,Year,Type,Genre,Poster,Trailer,Quality")] MovieListModel movieListModel) { if (ModelState.IsValid) { //Insert if (id == 0) { _context.Add(movieListModel); await _context.SaveChangesAsync(); } //Update else { try { _context.Update(movieListModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieListModelExists(movieListModel.MovieID)) { return(NotFound()); } else { throw; } } } return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAll", _context.MovieLists.ToList()) })); } return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", movieListModel) })); }
public async Task <IActionResult> Create([Bind("ApplicationResponseID,Category,Title,Year,Director,Rating,Edited,Lent_To,Notes")] ApplicationResponse applicationResponse) { if (ModelState.IsValid) { _context.Add(applicationResponse); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(applicationResponse)); }
public IActionResult NewMovies(Movies appResponse) { if (!ModelState.IsValid) { return(View()); } else { _context.Add(appResponse); _context.SaveChanges(); return(View("Confirmation", appResponse)); } }
public void Post([FromBody] MovieDTO value) { if (ModelState.IsValid) { //remove: data:image/png;base64, var onlyContent = value.ImageAsBase64.Substring(22); byte[] image = Convert.FromBase64String(onlyContent); Movie newMovie = new Movie { Title = value.Title, Year = value.Year, ScoreRating = value.ScoreRating, Image = image }; _context.Add(newMovie); _context.SaveChanges(); } }