Beispiel #1
0
        public async Task <IActionResult> OnPostAsync(int?id, string[]
                                                      selectedCategories)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var VinylToUpdate = await _context.Vinyl
                                .Include(i => i.Color)
                                .Include(i => i.VinylCategories)
                                .ThenInclude(i => i.Category)
                                .FirstOrDefaultAsync(s => s.ID == id);

            if (VinylToUpdate == null)
            {
                return(NotFound());
            }
            if (await TryUpdateModelAsync <Vinyl>(
                    VinylToUpdate,
                    "Vinyl",
                    i => i.Album, i => i.Artist,
                    i => i.Price, i => i.PublishingDate, i => i.Color))
            {
                UpdateVinylCategories(_context, selectedCategories, VinylToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            //Apelam UpdateVinylCategories pentru a aplica informatiile din checkboxuri la entitatea Vinyls care
            //este editata
            UpdateVinylCategories(_context, selectedCategories, VinylToUpdate);
            PopulateAssignedCategoryData(_context, VinylToUpdate);
            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.Attach(Color).State = EntityState.Modified;

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

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(string[] selectedCategories)
        {
            var newVinyl = new Vinyl();

            if (selectedCategories != null)
            {
                newVinyl.VinylCategories = new List <VinylCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new VinylCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newVinyl.VinylCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Vinyl>(
                    newVinyl,
                    "Vinyl",
                    i => i.Album, i => i.Artist,
                    i => i.Price, i => i.PublishingDate, i => i.ColorID))
            {
                _context.Vinyl.Add(newVinyl);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newVinyl);
            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.Color.Add(Color);
            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"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

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