コード例 #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 produsToUpdate = await _context.Produs
                                 .Include(i => i.Furnizor)
                                 .Include(i => i.CategoriiProduse)
                                 .ThenInclude(i => i.Categorie)
                                 .FirstOrDefaultAsync(s => s.ID == id);

            if (produsToUpdate == null)
            {
                return(NotFound());
            }
            if (await TryUpdateModelAsync <Produs>(produsToUpdate, "Produs",
                                                   i => i.Denumire, i => i.Producator,
                                                   i => i.Pret, i => i.DataDisponibilitatii, i => i.Furnizor))
            {
                UpdateCategoriiProduse(_context, selectedCategories, produsToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            //Apelam UpdateBookCategories pentru a aplica informatiile din checkboxuri la entitatea Books care
            //este editata
            UpdateCategoriiProduse(_context, selectedCategories, produsToUpdate);
            PopulateAssignedCategoryData(_context, produsToUpdate);
            return(Page());
        }
コード例 #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(CategorieProdus).State = EntityState.Modified;

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

            return(RedirectToPage("./Index"));
        }
コード例 #3
0
        public async Task <IActionResult> OnPostAsync(string[] selectedCategories)
        {
            var newProdus = new Produs();

            if (selectedCategories != null)
            {
                newProdus.CategoriiProduse = new List <CategorieProdus>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new CategorieProdus
                    {
                        CategorieID = int.Parse(cat)
                    };
                    newProdus.CategoriiProduse.Add(catToAdd);
                }
            }

            if (await TryUpdateModelAsync <Produs>(
                    newProdus,
                    "Produs",
                    i => i.Denumire, i => i.Producator,
                    i => i.Pret, i => i.DataDisponibilitatii, i => i.FurnizorID))
            {
                _context.Produs.Add(newProdus);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newProdus);
            return(Page());
        }
コード例 #4
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.Categorie.Add(Categorie);
            await _context.SaveChangesAsync();

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

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

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

            return(RedirectToPage("./Index"));
        }
コード例 #6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

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