コード例 #1
0
        public async Task <IActionResult> Create(string name, Guid[] selectedCategories)
        {
            if (!ModelState.IsValid)
            {
                return(Problem("erreur insertion db", "Error", 0, "Erreur"));
            }

            var model = new ProductModel();

            model.Id   = this.Id;
            model.Name = name;

            await _context.Products.AddAsync(model);

            await _context.Set <ProductCategorieModel>().AddRangeAsync(selectedCategories.Select(c => new ProductCategorieModel
            {
                Id          = System.Guid.NewGuid(),
                ProductId   = model.Id,
                CategorieId = c
            }));

            await _context.SaveChangesAsync();

            return(Redirect($"Details/{model.Id}"));
        }
コード例 #2
0
        public async Task <IActionResult> Delete(Guid id)
        {
            var categorie = await _context.Categories.FindAsync(id);

            _context.Categories.Remove(categorie);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }