// To protect from overposting attacks, 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(MovieRental).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MovieRentalExists(MovieRental.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
예제 #2
0
        // To protect from overposting attacks, 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.Movie.Add(Movie);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
예제 #3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MovieRental = await _context.MovieRental.FindAsync(id);

            if (MovieRental != null)
            {
                _context.MovieRental.Remove(MovieRental);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
예제 #4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            string isThereError = "false";

            ViewData["checkError"] = isThereError;
            if (id == null)
            {
                return(NotFound());
            }

            Movie = await _context.Movie.FindAsync(id);

            if (Movie != null)
            {
                _context.Movie.Remove(Movie);
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    ViewData["errorMessage"]            = ex.Message;
                    ViewData["customErrorMessagePart1"] = "If data is not deleted we recomend you to first delete this movie from video rentals";
                    ViewData["customErrorMessagePart2"] = "If error continue afterwards contact your IT support!";
                    isThereError           = "true";
                    ViewData["checkError"] = isThereError;
                }
            }
            if (isThereError == "true")
            {
                return(null);
            }
            else
            {
                return(RedirectToPage("./Index"));
            }


            // return null;
        }