// 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 flowerBoxToUpdate = await _context.FlowerBox
                                    .Include(i => i.Store)
                                    .Include(i => i.FlowerBoxCategories)
                                    .ThenInclude(i => i.Category)
                                    .FirstOrDefaultAsync(s => s.ID == id);

            if (flowerBoxToUpdate == null)
            {
                return(NotFound());
            }
            if (await TryUpdateModelAsync <FlowerBox>(
                    flowerBoxToUpdate,
                    "FlowerBox",
                    i => i.Series, i => i.Brand,
                    i => i.Price, i => i.AparitionDate, i => i.Size, i => i.StoreID))
            {
                UpdateFlowerBoxCategories(_context, selectedCategories, flowerBoxToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            //Apelam UpdateBookCategories pentru a aplica informatiile din checkboxuri la entitatea Books care
            //este editata
            UpdateFlowerBoxCategories(_context, selectedCategories, flowerBoxToUpdate);
            PopulateAssignedCategoryData(_context, flowerBoxToUpdate);
            return(Page());
        }
Beispiel #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 newFlowerBox = new FlowerBox();

            if (selectedCategories != null)
            {
                newFlowerBox.FlowerBoxCategories = new List <FlowerBoxCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new FlowerBoxCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newFlowerBox.FlowerBoxCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <FlowerBox>(
                    newFlowerBox,
                    "FlowerBox",
                    i => i.Series, i => i.Brand,
                    i => i.Price, i => i.AparitionDate, i => i.Size, i => i.StoreID))
            {
                _context.FlowerBox.Add(newFlowerBox);
                await _context.SaveChangesAsync();

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

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

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

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

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

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

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