コード例 #1
0
        public ActionResult AjouterParent(int id, FormAjouterParent fap)
        {
            Personne p = new PersonneServiceAPI().Donner(id);

            fap.idArbre = p.idArbre;

            IEnumerable <Personne> liste = new PersonneServiceAPI().DonnerParenteesDirectesPossibles(id);

            if (p.idPere != null)
            {
                liste = liste.Where(j => !j.homme);
            }
            if (p.idMere != null)
            {
                liste = liste.Where(j => j.homme);
            }

            if (liste.Where(j => j.id == fap.idParent).SingleOrDefault() == null)
            {
                return(View(fap));
            }

            if (ModelState.IsValid)
            {
                bool b = new PersonneServiceAPI().AjouterParent(new ParentEnfant {
                    idParent = fap.idParent, idEnfant = id
                });
                if (b)
                {
                    return(RedirectToAction("DonnerPourArbre", new { id = p.idArbre }));
                }
            }
            return(View(fap));
        }
コード例 #2
0
        public ActionResult AjouterParent(int id)
        {
            FormAjouterParent fap = new FormAjouterParent();
            Personne          p   = new PersonneServiceAPI().Donner(id);

            fap.idArbre = p.idArbre;
            IEnumerable <Personne> liste = new PersonneServiceAPI().DonnerParenteesDirectesPossibles(id);

            if (p.idPere != null)
            {
                liste = liste.Where(j => !j.homme);
            }
            if (p.idMere != null)
            {
                liste = liste.Where(j => j.homme);
            }

            fap.parents = liste.Select(j => new SelectListItem {
                Selected = false, Value = j.id.ToString(), Text = $"{j.VersAffichage()} ({j.homme.VersSexe()})"
            }).ToList();

            return(View(fap));
        }