示例#1
0
        public async Task <IActionResult> Create(SubCategorieEnCategorieViewModel model)
        {
            if (ModelState.IsValid)
            {
                var doesSubCategorieExists = _context.SubCategorie.Include(s => s.Categorie).Where(s => s.Subcategorie == model.SubCategorie.Subcategorie && s.Categorie.Id == model.SubCategorie.CategorieId);

                if (doesSubCategorieExists.Count() > 0)
                {
                    //Error
                    StatusBericht = "Foutmelding : Sub-Categorie bestaat reeds onder categorie " + doesSubCategorieExists.First().Categorie.Naam + ". Kies een andere naam aub.";
                }
                else
                {
                    _context.SubCategorie.Add(model.SubCategorie);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            SubCategorieEnCategorieViewModel modelVM = new SubCategorieEnCategorieViewModel()
            {
                CategorieLijst    = await _context.Categorie.ToListAsync(),
                SubCategorie      = model.SubCategorie,
                SubCategorieLijst = await _context.SubCategorie.OrderBy(p => p.Subcategorie).Select(p => p.Subcategorie).ToListAsync(),
                StatusBericht     = StatusBericht
            };

            return(View(modelVM));
        }
示例#2
0
        //GET- CREATE
        public async Task <IActionResult> Create()
        {
            SubCategorieEnCategorieViewModel model = new SubCategorieEnCategorieViewModel()
            {
                CategorieLijst    = await _context.Categorie.ToListAsync(),
                SubCategorie      = new Models.SubCategorie(),
                SubCategorieLijst = await _context.SubCategorie.OrderBy(p => p.Subcategorie).Select(p => p.Subcategorie).Distinct().ToListAsync()
            };

            return(View(model));
        }