Ejemplo n.º 1
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 jewelryToUpdate = await _context.Jewelry
                                  .Include(i => i.Material)
                                  .Include(i => i.JewelryCategories)
                                  .ThenInclude(i => i.Category)
                                  .FirstOrDefaultAsync(s => s.ID == id);

            if (jewelryToUpdate == null)
            {
                return(NotFound());
            }
            if (await TryUpdateModelAsync <Jewelry>(
                    jewelryToUpdate,
                    "Jewelry",
                    i => i.Product, i => i.Brand,
                    i => i.Price, i => i.ReleaseDate, i => i.Material))
            {
                UpdateJewelryCategories(_context, selectedCategories, jewelryToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            //Apelam UpdateBookCategories pentru a aplica informatiile din checkboxuri la entitatea Books care
            //este editata
            UpdateJewelryCategories(_context, selectedCategories, jewelryToUpdate);
            PopulateAssignedCategoryData(_context, jewelryToUpdate);
            return(Page());
        }
Ejemplo n.º 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.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 newJewelry = new Jewelry();

            if (selectedCategories != null)
            {
                newJewelry.JewelryCategories = new List <JewelryCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new JewelryCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newJewelry.JewelryCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Jewelry>(
                    newJewelry,
                    "Jewelry",
                    i => i.Product, i => i.Brand,
                    i => i.Price, i => i.ReleaseDate, i => i.MaterialID))
            {
                _context.Jewelry.Add(newJewelry);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newJewelry);
            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"));
        }
Ejemplo n.º 5
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"));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

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