// 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()); }
public IActionResult OnGet() { ViewData["StoreID"] = new SelectList(_context.Set <Store>(), "ID", "StoreName"); var flowerBox = new FlowerBox(); flowerBox.FlowerBoxCategories = new List <FlowerBoxCategory>(); PopulateAssignedCategoryData(_context, flowerBox); return(Page()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } FlowerBox = await _context.FlowerBox.FirstOrDefaultAsync(m => m.ID == id); if (FlowerBox == null) { return(NotFound()); } return(Page()); }
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")); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } FlowerBox = await _context.FlowerBox.Include(b => b.Store).Include(b => b.FlowerBoxCategories).ThenInclude(b => b.Category).AsNoTracking().FirstOrDefaultAsync(m => m.ID == id); if (FlowerBox == null) { return(NotFound()); } PopulateAssignedCategoryData(_context, FlowerBox); ViewData["StoreID"] = new SelectList(_context.Set <Store>(), "ID", "StoreName"); return(Page()); }
public async Task OnGetAsync(int?id, int?categoryID) { FlowerBoxD = new FlowerBoxData(); FlowerBoxD.FlowerBoxes = await _context.FlowerBox .Include(b => b.Store) .Include(b => b.FlowerBoxCategories) .ThenInclude(b => b.Category) .AsNoTracking() .OrderBy(b => b.Series) .ToListAsync(); if (id != null) { FlowerBoxID = id.Value; FlowerBox flowerBox = FlowerBoxD.FlowerBoxes .Where(i => i.ID == id.Value).Single(); FlowerBoxD.Categories = flowerBox.FlowerBoxCategories.Select(s => s.Category); } }