Esempio n. 1
0
        public ActionResult Create([Bind(Include = "Id,Matricule,Prenom,Nom,DateNaiss,Salaire,ServiceId")] Medecin medecin, int[] specialites)
        {
            if (ModelState.IsValid)
            {
                medecin.Specialites = new List <Specialite>();
                foreach (int sp in specialites)
                {
                    medecin.Specialites.Add(db.Specialites.Find(sp));
                }
                db.Medecins.Add(medecin);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(medecin));
        }
        public ActionResult Create([Bind(Include = "Id,Libelle")] Specialite specialite, int Service)
        {
            if (ModelState.IsValid)
            {
                Service service = db.Services.Find(Service);
                specialite.Service = service;
                Specialite spExist = db.Specialites.SingleOrDefault(sp => sp.Libelle == (specialite.Libelle));
                if (spExist != null)
                {
                    return(RedirectToAction("Create"));
                }
                db.Specialites.Add(specialite);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(specialite));
        }
Esempio n. 3
0
        public ActionResult Specialite(int Id, int[] specialites)
        {
            using (var db = new RhContext())
            {
                Medecin medecin = db.Medecins.Find(Id);
                medecin.Specialites = new List <Specialite>();
                foreach (int sp in specialites)
                {
                    medecin.Specialites.Add(db.Specialites.Find(sp));
                }
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 4
0
        public ActionResult Affecter(int Id, int ServiceId)
        {
            using (var db = new RhContext())
            {
                IQueryable <Medecin> queryable = db.Medecins.Where(m => m.Id == Id);
                var medecin = queryable.Include(r => r.Specialites).FirstOrDefault();
                medecin.ServiceId = ServiceId;
                foreach (Specialite specialite in medecin.Specialites.ToList())
                {
                    medecin.Specialites.Remove(specialite);
                }
                db.SaveChanges();
            }



            return(RedirectToAction("Index"));
        }