public async Task <ActionResult> UpdateMovie([FromForm] MovieModel moviemodel) { if (!ModelState.IsValid) { return(Ok(new { error = "Error While adding movie" })); } /* new movie object */ MoviesDataModel movie = new MoviesDataModel { name = moviemodel.name, id = moviemodel.id, about = moviemodel.about, }; //add image if applicable if (moviemodel.thumb != null) { UploadImage(moviemodel.thumb); movie.image = moviemodel.thumb.FileName; } _db.Movies.Update(movie); await _db.SaveChangesAsync(); return(Ok(new { message = "Movie updated...!" })); }
public async Task <ActionResult> AddNewMovie([FromForm] MovieModel moviemodel) { if (!ModelState.IsValid) { return(Ok(new { error = "Error While adding movie" })); } /* Upload the image */ UploadImage(moviemodel.thumb); /* inititalize a new movie object */ MoviesDataModel movie = new MoviesDataModel { name = moviemodel.name, about = moviemodel.about, image = moviemodel.thumb.FileName }; /* ad new movie to collection */ _db.Movies.Add(movie); await _db.SaveChangesAsync(); return(Ok(new { message = "Succesfully added...!" })); }
/// <summary> /// write movies to the JSON /// </summary> /// <param name="movies">the movies to save</param> private void writeMoviesToJson(IEnumerable <MovieDataModel> movies) { var moviesDto = new MoviesDataModel() { movies = movies }; var moviesJsonString = JsonConvert.SerializeObject(moviesDto); File.WriteAllText(moviesJson, moviesJsonString); }