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(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Create([Bind("ID,Title,ReleaseDate,Genre,Homepage")] Movie movie) { if (ModelState.IsValid) { movie.UserID = Convert.ToInt32(TempData.Peek("Userid")); _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Create([Bind("UserID,UserName, Password,ConfirmPassword")] User user) { var dbuser = await _context.User.SingleOrDefaultAsync(m => m.UserName == user.UserName); if (dbuser != null) { TempData["ERROR"] = "UserName has been taken"; return(View(user)); } if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Login))); } return(View(user)); }
public async Task <IActionResult> MovieDetail(int mid, Movie movie) { if (TempData.Peek("UserId") == null) { System.Threading.Thread.Sleep(8000); //return RedirectToAction("Login", "User"); return(View()); } else { var client = new RestClient("https://api.themoviedb.org/3/movie/" + mid + "?api_key=b7f9af2647fdef6d0633f07337802317"); var request = new RestRequest(Method.GET); request.AddParameter("undefined", "{}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); Dictionary <string, object> Mdetails = JsonConvert.DeserializeObject <Dictionary <string, object> >(response.Content); movie.Title = Convert.ToString(Mdetails["title"]); movie.ReleaseDate = Convert.ToDateTime(Mdetails["release_date"]); var genresList = (Mdetails["genres"] as IEnumerable).Cast <object>().Select(x => x.ToString()).ToArray(); var temp = ""; for (int i = 0; i < genresList.Length; i++) { Dictionary <string, object> genresdic = JsonConvert.DeserializeObject <Dictionary <string, object> >(genresList[i]); //Trace.WriteLine("hhhhh " + genresdic["name"]); temp = temp + genresdic["name"] + "; "; } movie.Genre = temp; movie.UserID = Convert.ToInt32(TempData.Peek("UserId")); movie.Homepage = Convert.ToString(Mdetails["homepage"]); _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Movies")); } }