// 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(Category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(Category.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        // 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(string[] selectedCategories)
        {
            var newFilm = new Film();

            if (selectedCategories != null)
            {
                newFilm.FilmCategories = new List <FilmCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new FilmCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newFilm.FilmCategories.Add(catToAdd);
                }
            }


            if (await TryUpdateModelAsync <Film>(
                    newFilm,
                    "Film",
                    i => i.Title, i => i.Length,
                    i => i.Price, i => i.ReleaseDate, i => i.DirectorID))
            {
                _context.Film.Add(newFilm);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            PopulateAssignedCategoryData(_context, newFilm);
            return(Page());
        }
예제 #3
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(int?id, string[] selectedCategories)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var filmToUpdate = await _context.Film
                               .Include(i => i.Director)
                               .Include(i => i.FilmCategories)
                               .ThenInclude(i => i.Category)
                               .FirstOrDefaultAsync(s => s.ID == id);

            if (filmToUpdate == null)
            {
                return(NotFound());
            }

            if (await TryUpdateModelAsync <Film>(
                    filmToUpdate,
                    "Film",
                    i => i.Title, i => i.Length,
                    i => i.Price, i => i.ReleaseDate, i => i.Director))
            {
                UpdateFilmCategories(_context, selectedCategories, filmToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            UpdateFilmCategories(_context, selectedCategories, filmToUpdate);
            PopulateAssignedCategoryData(_context, filmToUpdate);
            return(Page());
        }
        // 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.Category.Add(Category);
            await _context.SaveChangesAsync();

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

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

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

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

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

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

            return(RedirectToPage("./Index"));
        }