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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RecordExists(Record.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 newAlbum = new Album();

            if (selectedCategories != null)
            {
                newAlbum.AlbumCategories = new List <AlbumCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new AlbumCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newAlbum.AlbumCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Album>(
                    newAlbum,
                    "Album",
                    i => i.Title, i => i.Singer,
                    i => i.Price, i => i.PublishingDate, i => i.RecordID))
            {
                _context.Album.Add(newAlbum);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newAlbum);
            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(int?id, string[]
                                                      selectedCategories)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var AlbumToUpdate = await _context.Album
                                .Include(i => i.Record)
                                .Include(i => i.AlbumCategories)
                                .ThenInclude(i => i.Category)
                                .FirstOrDefaultAsync(s => s.ID == id);

            if (AlbumToUpdate == null)
            {
                return(NotFound());
            }
            if (await TryUpdateModelAsync <Album>(
                    AlbumToUpdate,
                    "Album",
                    i => i.Title, i => i.Singer,
                    i => i.Price, i => i.PublishingDate, i => i.Record))
            {
                UpdateAlbumCategories(_context, selectedCategories, AlbumToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            //Apelam UpdateAlbumCategories pentru a aplica informatiile din checkboxuri la entitatea Albums care
            //este editata
            UpdateAlbumCategories(_context, selectedCategories, AlbumToUpdate);
            PopulateAssignedCategoryData(_context, AlbumToUpdate);
            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.Record.Add(Record);
            await _context.SaveChangesAsync();

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

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

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

            return(RedirectToPage("./Index"));
        }
Exemple #6
0
        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"));
        }