Exemplo n.º 1
0
        // GET: Groupes/Create
        public IActionResult Create()
        {
            var employes = from e in _context.Employes
                           join p in _context.Personnes on e.EmployeId equals p.PersonneId
                           select(new
            {
                EmployeId = e.EmployeId,
                Nom       = p.Prenom + " " + p.Nom
            });

            var createGroupeVM = new CreateGroupeViewModel();

            createGroupeVM.Referants   = new SelectList(employes, "EmployeId", "Nom");
            createGroupeVM.TypesGroupe = new SelectList(_context.TypesGroupe, "TypeGroupeId", "Libelle");
            return(View(createGroupeVM));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(CreateGroupeViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Groupe groupe = new Groupe();
                groupe.Descriptif   = viewModel.Descriptif;
                groupe.ReferantId   = viewModel.Referant;
                groupe.TypeGroupeId = viewModel.TypeGroupe;
                groupe.Visible      = 1;
                _context.Add(groupe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            CreateGroupeViewModel createGroupeVM = new CreateGroupeViewModel
            {
                Referants   = new SelectList(await _context.Employes.Include(e => e.Personne).Distinct().ToListAsync(), "EmployeId", "Personne.Nom", viewModel.Referant),
                TypesGroupe = new SelectList(_context.TypesGroupe, "TypeGroupeId", "Libelle", viewModel.TypeGroupe)
            };

            return(View(createGroupeVM));
        }