public HttpResponseMessage Delete(int Id) { try { if (ModelState.IsValid) { var context = new MovieDb(); //If Id Not found if (_movieDb.Query<Movie>().Any(m => m.Id == Id) == false) { return Request.CreateResponse(HttpStatusCode.NotFound, "Record Not found with the ID supplied"); } //else delete if (_movieDb.Query<Movie>().Any(m => m.Id == Id)) { Movie movie = context.Movies.Find(Id); context.Movies.Remove(movie); context.SaveChanges(); } } } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
public JsonResult Index() { var _db = new MovieDb(Server.MapPath("movie.json")); var movies = _db.SelectAllMovies(); return(Json(movies, JsonRequestBehavior.AllowGet)); }
public HttpResponseMessage Delete(int Id) { try { if (ModelState.IsValid) { var context = new MovieDb(); //If Id Not found if (_movieDb.Query <Movie>().Any(m => m.Id == Id) == false) { return(Request.CreateResponse(HttpStatusCode.NotFound, "Record Not found with the ID supplied")); } //else delete if (_movieDb.Query <Movie>().Any(m => m.Id == Id)) { Movie movie = context.Movies.Find(Id); context.Movies.Remove(movie); context.SaveChanges(); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public HttpResponseMessage Put([FromBody] Movie movie) { try { if (ModelState.IsValid) { var context = new MovieDb(); //If Id Not found if (_movieDb.Query <Movie>().Any(m => m.Id == movie.Id) == false) { return(Request.CreateResponse(HttpStatusCode.NotFound, "Record Not found with the ID supplied")); } //If Id found, then go ahead and update the record if (_movieDb.Query <Movie>().Any(m => m.Id == movie.Id)) { context.Movies.AddOrUpdate(movie); context.SaveChanges(); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
private async Task <HttpResponseMessage> AddMovieRankData(int testUserId, string movieName = "Test-MovieName") { var movieDbData = new MovieDb { UserId = testUserId, MovieName = movieName, Description = "test-Description", Actors = new List <string> { "testUser1", "testUser2" }, RankedDateTime = "5/10/2018 6:17:17 PM", Ranking = 4 }; var json = JsonConvert.SerializeObject(movieDbData); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); try { return(await sut.Client.PostAsync($"movies/{testUserId}", stringContent)); } catch (Exception ex) { throw ex; } }
public ActionResult DeleteConfirmed(int id) { Movie movie = db.Movies.Find(id); MovieDb.DeleteMovie(db, movie); return(RedirectToAction("Index")); }
// GET: Profiles/Create public ActionResult Create() { ProfileMoviesJobsViewModel model = new ProfileMoviesJobsViewModel { AllMovies = MovieDb.GetAllMovies(db), AllJobs = JobDb.GetAllJobs(db) }; return(View(model)); }
public MovieRankResponse ToMovieContract(MovieDb movie) { return(new MovieRankResponse { MovieName = movie.MovieName, Description = movie.Description, Actors = movie.Actors, Ranking = movie.Ranking, TimeRanked = movie.RankedDateTime }); }
public MovieDb ToMovieDbModel(int userId, MovieDb movie, MovieUpdateRequest movieUpdateRequest) { return(new MovieDb { UserId = userId, MovieName = movie.MovieName, Description = movie.Description, Actors = movie.Actors, Ranking = movieUpdateRequest.Ranking, RankedDateTime = DateTime.UtcNow.ToString() }); }
public MovieResponse ToMovieContract(MovieDb item) { return(new MovieResponse { UserId = item.UserId, MovieName = item.MovieName, Description = item.Description, Actors = item.Actors, Ranking = item.Ranking, TimeRanked = item.RankedDateTime }); }
public ActionResult Edit([Bind(Include = "ID,Title,ReleaseDate,UserRating,MPAARating,MovieLength" + ",Genre,Description,MoviePoster")] Movie movie) { if (ModelState.IsValid) { MovieDb.UpdateMovie(db, movie); return(RedirectToAction("Index")); } return(View(movie)); }
public MovieDb ToMovieDbModel(int userId, MovieDb current, MovieUpdateRequest updated) { return(new MovieDb { UserId = userId, MovieName = current.MovieName, Description = current.Description, Actors = current.Actors, Ranking = updated.Ranking, RankedDateTime = DateTime.UtcNow.ToString() }); }
// GET: Movies/Delete/5 public ActionResult Delete(int?id) { if (!id.HasValue) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Movie movie = MovieDb.GetMovie(db, id.Value); if (movie == null) { return(HttpNotFound()); } return(View(movie)); }
protected override void Seed(MovieDb context) { context.Movies.AddOrUpdate(m => m.Title, new Movie { Title = "Star Wars", ReleaseYear = 1977, Runtime = 121 }, new Movie { Title = "E.T.", ReleaseYear = 1981, Runtime = 130 }, new Movie { Title = "Toy Story", ReleaseYear = 1994, Runtime = 90 } ); }
public MovieResponse ToMovieContract(MovieDb movie) { var dothecalc = movie.GetAMagicNumberFromMe(); var dothecalcfac = movie.GetAMagicNumberFromMe() * 199; return(new MovieResponse { MovieName = movie.MovieName, Description = movie.Description, Actors = movie.Actors, Ranking = movie.Ranking, RankedDateTime = movie.RankedDateTime }); }
public MainWindow() { InitializeComponent(); LogViewer.DisplayLevel = Level.Debug; IMovieDb db = new MovieDb(); _configReader = new ConfigReader(); _scanner = new BasicFileScanner(); _analyzer = new FileAnalyzer(db); _movideo = new MovideoApp(_configReader, _scanner, _analyzer, db); _movideo.MatchFound += _movideo_MatchFound; _movideo.ProgressChanged += _movideo_ProgressChanged; }
public async Task MovieDb_Return_Success() { //arrange var httpClient = new Mock <IHttpClient>(); var jsonSerializer = new Mock <IJsonSerializer>(); var applicationHost = new Mock <IApplicationHost>(); var responseModel = new MovieInformation() { Id = 123, Imdb_Id = "123", Title = "Test", release_date = DateTime.Now, Original_Title = "Test" }; var responseStream = Utility.GenerateStreamFromString(JsonSerializer.Serialize(responseModel)); jsonSerializer .Setup(_ => _.DeserializeFromStream <It.IsAnyType>(responseStream)) .Returns(() => JsonSerializer.Deserialize(responseStream, typeof(MovieInformation), new JsonSerializerOptions())); httpClient .Setup(_ => _.GetResponse(It.IsAny <HttpRequestOptions>())) .ReturnsAsync(() => new HttpResponseInfo() { ContentLength = 1, ContentType = "application/json", Content = responseStream }); applicationHost .Setup(_ => _.ApplicationVersion) .Returns(() => new Version("1.1.1.1")); var movieDb = new MovieDb(jsonSerializer.Object, httpClient.Object, applicationHost.Object); //act var response = await movieDb.GetMovieInfo("123", CancellationToken.None); //assert response.Should().NotBeNull(); response.Id.Should().Be(123); response.Imdb_Id.Should().Be("123"); }
private static MovieResponse MovieResponse(MovieDb c) { if (c == null) { return(new MovieResponse()); } var response = new MovieResponse { UserId = c.UserId, Description = c.Description, Actors = c.Actors, RankedDateTime = c.RankedDateTime, MovieName = c.MovieName, Ranking = c.Ranking }; return(response); }
public ActionResult AddMovie(MovieDb movie, HttpPostedFileBase file) { if (file != null) { file.SaveAs(HttpContext.Server.MapPath("~/Content/Images/") + file.FileName); movie.PictureLink = file.FileName; } movie.Added = DateTime.Now.ToString(); db.MovieDb.Add(movie); try { db.SaveChanges(); RedirectToAction("Index"); } catch (DbEntityValidationException ex) { } return(View()); }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return(RedirectToAction("Manage")); } if (ModelState.IsValid) { // Insert a new user into the database using (var db = new MovieDb()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); db.SaveChanges(); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return(View(model)); }
private async Task <HttpResponseMessage> AddMovieRankData(int userId, string movieName = "Test-MovieName") { var movieDbData = new MovieDb() { UserId = userId, MovieName = movieName, Description = "test-Description", Actors = new List <string>() { "testUser1", "testUser2" }, Ranking = 7, RankedDateTime = "8/12/2019 2:22:22 PM" }; var json = JsonConvert.SerializeObject(movieDbData); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); return(await _sut.Client.PostAsync($"movies/{userId}", stringContent)); }
// GET: Profiles/Edit/5 public ActionResult Edit(int?id) { if (!id.HasValue) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Profile profile = ProfileDb.FindProfile(db, id.Value); if (profile == null) { return(HttpNotFound()); } ProfileMoviesJobsViewModel model = new ProfileMoviesJobsViewModel { Profile = profile, AllMovies = MovieDb.GetAllMovies(db), AllJobs = JobDb.GetAllJobs(db) }; return(View(model)); }
public object Post([FromBody] Movie movie) { try { if (ModelState.IsValid) { var context = new MovieDb(); //Check Duplicate if (_movieDb.Query<Movie>().Any(m => m.Id == movie.Id)) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Entry with the Id already exist"); } context.Movies.Add(movie); context.SaveChanges(); } } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex); } return Request.CreateResponse(HttpStatusCode.Created); }
public object Post([FromBody] Movie movie) { try { if (ModelState.IsValid) { var context = new MovieDb(); //Check Duplicate if (_movieDb.Query <Movie>().Any(m => m.Id == movie.Id)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Entry with the Id already exist")); } context.Movies.Add(movie); context.SaveChanges(); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } return(Request.CreateResponse(HttpStatusCode.Created)); }
protected override void Seed(MovieDb context) { context.Movies.AddOrUpdate(m => m.Title, new Movie { Title = "Star Wars", ReleaseYear = 1977, Runtime = 121 }, new Movie { Title = "Inception", ReleaseYear = 2010, Runtime = 148 }, new Movie { Title = "Toy Story", ReleaseYear = 1995, Runtime = 81 } ); }
public static void Main() { var movie1 = new Movie { Id = 1, Title = "Godzilla" }; var movie2 = new Movie { Id = 2, Title = "Iron Man" }; using (var context = new MovieDb()) { /* context.Database.Log = (s) => { Console.WriteLine(s); }; */ Console.WriteLine("========= Start Add: movie1 =============="); context.Movies.Add(movie1); context.SaveChanges(); Console.WriteLine("========= END Add: movie1 =============="); // LET EF CREATE ALL THE SCHEMAS AND STUFF THEN WE CAN TEST context.Database.Log = (s) => { Console.WriteLine(s); }; Console.WriteLine("========= Start SELECT FIRST movie =============="); var movie1a = context.Movies.First(); Console.WriteLine("========= End SELECT FIRST movie =============="); Console.WriteLine("========= Start Attach Movie2 =============="); context.Movies.Attach(movie2); Console.WriteLine("========= End Attach Movie2 =============="); Console.WriteLine("========= Start SELECT Movie2 =============="); var movie2a = context.Movies.FirstOrDefault(m => m.Id == 2); Console.WriteLine("========= End SELECT Movie2 =============="); Console.Write("Movie2a.Id = "); Console.WriteLine(movie2a == null ? "null" : movie2a.Id.ToString()); } }
public HttpResponseMessage Put([FromBody] Movie movie) { try { if (ModelState.IsValid) { var context = new MovieDb(); //If Id Not found if (_movieDb.Query<Movie>().Any(m => m.Id == movie.Id) == false) { return Request.CreateResponse(HttpStatusCode.NotFound, "Record Not found with the ID supplied"); } //If Id found, then go ahead and update the record if (_movieDb.Query<Movie>().Any(m => m.Id == movie.Id)) { context.Movies.AddOrUpdate(movie); context.SaveChanges(); } } } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
public MoviesController(MovieDb db) { _db = db; }
public async Task UpdateMovie(MovieDb movie) { await _context.SaveAsync(movie); }
// GET: Movies public ActionResult Index() { return(View(MovieDb.GetAllMovies(db))); }
public async Task UpdateMovie(MovieDb movieDb) { // SaveAsync is also used in updating an item await _context.SaveAsync <MovieDb>(movieDb); }
public async Task AddMovie(MovieDb movieDb) { // save the model to the dynamodb table await _context.SaveAsync <MovieDb>(movieDb); }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return RedirectToAction("Manage"); } if (ModelState.IsValid) { // Insert a new user into the database using (var db = new MovieDb()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); db.SaveChanges(); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return RedirectToLocal(returnUrl); } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return View(model); }
public async Task UpdateMovie(MovieDb request) { await _context.SaveAsync(request); }