public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Movie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { // 处理并发异常,一个用户编辑了电影,另一个用户立即删除电影,则前一个用户保存时会出现并发问题。 if (!MovieExists(Movie.ID)) { return(NotFound()); } else { throw; } } // 注意区别./Index 和 Index 是当前路径下的Index页面,/Index是根目录Pages下面的Index页面 return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Movie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } // TODO Production code may want to detect concurrency conflicts. See Handle concurrency conflicts for more information. catch (DbUpdateConcurrencyException) { if (!MovieExists(Movie.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Movie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } //this handles if a movie has been deleted by one client while being edited by another catch (DbUpdateConcurrencyException) { if (!MovieExists(Movie.ID)) { return(NotFound()); } else { throw; } } //if no errors, return to the list return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { // Use LINQ to get list of genres. IQueryable <string> genreQuery = from m in _context.MyMovie orderby m.Genre select m.Genre; var movies = from m in _context.MyMovie select m; if (!ModelState.IsValid) { return(Page()); } _context.Attach(MyMovie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MyMovieExists(MyMovie.MyMovieID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Movie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!_context.Movie.Any(e => e.ID == Movie.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Movie.Add(Movie); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new RazorPagesMovieContext(serviceProvider.GetRequiredService <DbContextOptions <RazorPagesMovieContext> >())) { if (context.Movie.Any()) { return; } context.Movie.AddRange( new Movie { Title = "When Harry Met Sally", ReleaseDate = DateTime.Parse("1989-2-12"), Genre = "Romantic Comedy", Price = 7.99M, Rating = "R" }, new Movie { Title = "Ghostbusters ", ReleaseDate = DateTime.Parse("1984-3-13"), Genre = "Comedy", Price = 8.99M, Rating = "G" }, new Movie { Title = "Ghostbusters 2", ReleaseDate = DateTime.Parse("1986-2-23"), Genre = "Comedy", Price = 9.99M, Rating = "G" }, new Movie { Title = "Rio Bravo", ReleaseDate = DateTime.Parse("1959-4-15"), Genre = "Western", Price = 3.99M, Rating = "NA" } ); context.SaveChangesAsync(); } }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Schedule = await _context.Schedule.FindAsync(id); if (Schedule != null) { _context.Schedule.Remove(Schedule); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { // Si al rellenar el formulario hay algun error, no se // insertan los datos en la BD y se recarga el fórmulario if (!ModelState.IsValid) { return(Page()); } // Si no hay errores, se guardan los datos _context.Movie.Add(Movie); await _context.SaveChangesAsync(); // Y redirecionamos a la página Index return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Person = await _context.Person.FindAsync(id); if (Person != null) { _context.Person.Remove(Person); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } MyLittleEntity = await _context.MyLittleEntity.FindAsync(id); if (MyLittleEntity != null) { _context.MyLittleEntity.Remove(MyLittleEntity); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(string?id) { if (id == null) { return(NotFound()); } Movie2 = await _context.Movie2.FindAsync(id); if (Movie2 != null) { _context.Movie2.Remove(Movie2); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Test2 = await _context.Test2.FindAsync(id); if (Test2 != null) { _context.Test2.Remove(Test2); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Movie = await _context.ReportList.FindAsync(id); if (Movie != null) { _context.ReportList.Remove(Movie); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Customer = await _context.Customer.FindAsync(id); if (Customer != null) { _context.Customer.Remove(Customer); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Movie = await _context.Movie.FindAsync(id); if (Movie != null) // reaches back to RazorPagesMovieContext to delete Movie from the db { _context.Movie.Remove(Movie); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { // Perform an initial check to catch FileUpload class // attribute violations. if (!ModelState.IsValid) { Schedule = await _context.Schedule.AsNoTracking().ToListAsync(); return(Page()); } var publicScheduleData = await FileHelpers.ProcessFormFile(FileUpload.UploadPublicSchedule, ModelState); var privateScheduleData = await FileHelpers.ProcessFormFile(FileUpload.UploadPrivateSchedule, ModelState); // Perform a second check to catch ProcessFormFile method // violations. if (!ModelState.IsValid) { Schedule = await _context.Schedule.AsNoTracking().ToListAsync(); return(Page()); } var schedule = new Schedule() { PublicSchedule = publicScheduleData, PublicScheduleSize = FileUpload.UploadPublicSchedule.Length, PrivateSchedule = privateScheduleData, PrivateScheduleSize = FileUpload.UploadPrivateSchedule.Length, Title = FileUpload.Title, UploadDT = DateTime.UtcNow }; _context.Schedule.Add(schedule); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { //check for initial validation errors if (!ModelState.IsValid) { Schedule = await _context.Schedule.AsNoTracking().ToListAsync(); return(Page()); } //check for file validation errors var publicScheduleData = await FileHelper.ProcessFormFile(FileUpload.UploadPublicSchedule, ModelState); var privateScheduleData = await FileHelper.ProcessFormFile(FileUpload.UploadPrivateSchedule, ModelState); if (!ModelState.IsValid) { Schedule = await _context.Schedule.AsNoTracking().ToListAsync(); return(Page()); } //post to database var schedule = new Schedule() { PrivateSchedule = privateScheduleData, PrivateScheduleSize = FileUpload.UploadPrivateSchedule.Length, PublicSchedule = publicScheduleData, PublicScheduleSize = FileUpload.UploadPublicSchedule.Length, Title = FileUpload.Title, UploadDT = DateTime.UtcNow }; _context.Schedule.Add(schedule); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { string[] title = Movie2.Title.Split(); List <string> newtitle = new List <string>(); int counter = 0; foreach (var word in title) { if (counter != 0 || counter != title.Length - 1) { newtitle.Add(word); newtitle.Add("+"); } else { newtitle.Add(word); } counter = counter++; } Movie2 movie = await Backend.Api.GetMovieAsync(Movie2.Title); if (!ModelState.IsValid) { return(Page()); } _context.Movie2.Add(movie); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var str = getMovieInfo(Movie.Title); JObject json = JObject.Parse(str); foreach (JProperty prop in (JToken)(json)) { var key = prop.Name; var jvalue = prop.Value; if (key == "Ratings") { //Create a list with all ratings List <double> avgRating = new List <double>(); foreach (JObject parsedObject in jvalue.Children <JObject>()) { var rating = parsedObject["Value"].ToString(); //convert all the ratings to 1 to 10 scale //convert percentage based rating to 1 to 10 scale (example : 88% ==> 8.8) if (rating.Contains("%")) { avgRating.Add(fromPercentageRatingToDouble(rating)); } else if (rating.Contains("/")) { var tempRating = rating.Remove(rating.IndexOf("/")); //7.5/10 ==> 7.5 if (tempRating.Contains(".")) { avgRating.Add(double.Parse(tempRating)); } else { // 75/100 ==> 7.5 avgRating.Add(double.Parse(tempRating) / 10); } } else { try { avgRating.Add(double.Parse(rating)); } catch (Exception ex) { continue; } } } //assign the average rating Movie.Ratings = "Avarage rating (1 to 10 Scale) : " + String.Format("{0:0.00}", avgRating.Average()); } else if (key == "Poster" && !string.IsNullOrWhiteSpace(jvalue.ToString())) { Movie.PosterArt = jvalue.ToString(); } } _context.Movie.Add(Movie); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }