Example #1
0
        public void Edit(Matiere m)
        {
            //this.context.Matieres.Attach(m);
            //var objectContext = ((IObjectContextAdapter)context).ObjectContext;
            //var u = m.Ue;
               // m.Ue = null;
            this.context.Entry(m).State = EntityState.Modified;

              //  objectContext.ObjectStateManager.ChangeObjectState(m, EntityState.Modified);

              //  m.Ue = u;
            //    this.context.SaveChanges();
             /*  this.context.Entry(m).Reference(p => p.Ue).Load();
               var u = m.Ue;
               //this.context.Entry(m).State = EntityState.Modified;
               this.context.SaveChanges();*/
        }
        public ActionResult EditMatiere(Matiere matiere)
        {
            System.Diagnostics.Debug.WriteLine("LOLO" + matiere.Id);
            Matiere m = this.matiereRepository.GetEager(matiere.Id);
            m.Ue = this.ueRepository.Get(matiere.Ue.Id);
            m.Libelle = matiere.Libelle;

            if (ModelState.IsValid)
            {
                this.matiereRepository.Edit(m);
                this.matiereRepository.Save();
                return RedirectToAction("IndexMatiere");
            }

            return View(m);
        }
        public ActionResult CreateMatiere(Matiere matiere)
        {
            matiere.Ue = this.ueRepository.Get(matiere.Ue.Id);
            foreach (ModelState modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    System.Diagnostics.Debug.WriteLine(error.ErrorMessage);
                }
            }
            if (ModelState.IsValid)
            {
                this.matiereRepository.Insert(matiere);
                this.matiereRepository.Save();
                return RedirectToAction("IndexMatiere");
            }

            return View(matiere);
        }