public ActionResult EditEleve(Guid id)
        {
            EleveModels model;

            using (EleveRepository repository = new EleveRepository())
            {
                IQueryable <Tutors>     tuteurs = repository.GetTutors();
                IQueryable <Classrooms> classes = repository.GetClasses();
                IQueryable <Levels>     niveaux = repository.GetNiveaux();
                Pupils x = repository.GetPupilById(id);
                model = new EleveModels
                {
                    mode         = 0,
                    state        = short.MaxValue,
                    firstName    = x.FirstName,
                    lastName     = x.LastName,
                    sexe         = x.Sex,
                    birthdayDate = x.BirthdayDate,
                    tuteurId     = x.Tutor_Id,
                    classroomId  = x.Classroom_Id,
                    levelId      = x.Level_Id,
                    tuteurs      = getListTuteurs(tuteurs),
                    classes      = getListClasses(classes),
                    niveaux      = getListNiveaux(niveaux)
                };
            }
            return(View("CreateEleve", model));
        }
        public ActionResult DeleteEleve(Guid id)
        {
            EleveModels model;

            using (EleveRepository repository = new EleveRepository())
            {
                Pupils x = repository.GetPupilById(id);
                if (x == null)
                {
                    return(HttpNotFound());
                }
                model = new EleveModels
                {
                    id           = x.Id,
                    firstName    = x.FirstName,
                    lastName     = x.LastName,
                    sexe         = x.Sex,
                    birthdayDate = x.BirthdayDate,
                    tuteurId     = x.Tutor_Id,
                    classroomId  = x.Classroom_Id,
                    levelId      = x.Level_Id
                                   // tuteurs =
                                   // classroom =
                                   // level =
                                   // result =
                };
            }


            return(View("DeleteEleve", model));
        }
        public ActionResult CreateEleve(EleveModels model)
        {
            if (ModelState.IsValid)
            {
                using (EleveRepository repository = new EleveRepository())
                {
                    Pupils a = new Pupils
                    {
                        Id           = Guid.NewGuid(),
                        State        = short.MaxValue,
                        FirstName    = model.firstName,
                        LastName     = model.lastName,
                        Sex          = model.sexe,
                        BirthdayDate = model.birthdayDate,
                        Tutor_Id     = model.tuteurId,
                        Classroom_Id = model.classroomId,
                        Level_Id     = model.levelId
                                       // tuteurs =
                                       // classroom =
                                       // level =
                                       // result =
                    };

                    repository.Add(a);
                    repository.Save();
                }
                return(RedirectToAction("ReadEleves"));
            }
            return(View(model));
        }
        public ActionResult SearchEleves(String query)
        {
            IList <EleveModels> models = new List <EleveModels>();

            using (EleveRepository repository = new EleveRepository())
            {
                IQueryable <Pupils> a = repository.All();

                models = repository.GetElevesByQuery(query).Select(x => new EleveModels
                {
                    id           = x.Id,
                    firstName    = x.FirstName,
                    lastName     = x.LastName,
                    sexe         = x.Sex,
                    birthdayDate = x.BirthdayDate,
                    tuteurId     = x.Tutor_Id,
                    classroomId  = x.Classroom_Id,
                    levelId      = x.Level_Id
                                   // tuteurs =
                                   // classroom =
                                   // level =
                                   // result =
                }).ToList();
            }
            return(PartialView("_elevesList", models));
        }
        // GET: /Eleves/CreateEleve
        public ActionResult CreateEleve(Guid?classe, Guid?level, Guid?tuteur)
        {
            EleveModels model;

            using (EleveRepository repository = new EleveRepository())
            {
                IQueryable <Tutors>     tuteurs = repository.GetTutors();
                IQueryable <Classrooms> classes = repository.GetClasses();
                IQueryable <Levels>     niveaux = repository.GetNiveaux();
                model = new EleveModels
                {
                    mode    = -1,
                    tuteurs = getListTuteurs(tuteurs),
                    classes = getListClasses(classes),
                    niveaux = getListNiveaux(niveaux),
                };
                if (classe != null)
                {
                    model.classroomId = (Guid)classe;
                }
                if (level != null)
                {
                    model.levelId = (Guid)level;
                }
                if (tuteur != null)
                {
                    model.tuteurId = (Guid)tuteur;
                }
            }
            return(View(model));
        }
        public ActionResult ReadEleve(Guid id)
        {
            EleveModels model;

            using (EleveRepository repository = new EleveRepository())
            {
                Pupils x = repository.GetPupilById(id);
                IQueryable <Tutors>      t = repository.GetTutors();
                IQueryable <Results>     r = repository.GetResultatsByPupilId(id);
                IQueryable <Evaluations> e = repository.GetEvaluations();
                if (x == null)
                {
                    return(HttpNotFound());
                }
                model = new EleveModels
                {
                    id           = x.Id,
                    firstName    = x.FirstName,
                    lastName     = x.LastName,
                    sexe         = x.Sex,
                    birthdayDate = x.BirthdayDate,
                    tuteurId     = x.Tutor_Id,
                    classroomId  = x.Classroom_Id,
                    levelId      = x.Level_Id,
                    tuteurName   = x.Tutors.LastName,
                    classTitle   = x.Classrooms.Title,
                    niveauName   = x.Levels.Title,
                    resultats    = getListResultats(r),
                    evaluations  = getListEvaluations(e)
                };
            }
            return(View(model));
        }
 public ActionResult DeleteEleve(EleveModels model)
 {
     using (EleveRepository repository = new EleveRepository())
     {
         repository.DeleteById(model.id);
         repository.Save();
     }
     return(View("Index"));
 }
        // EXPORT EXCEL
        public ActionResult ExportExcel()
        {
            GridView gv = new GridView();

            IList <EleveModels> models = new List <EleveModels>();

            using (EleveRepository repository = new EleveRepository())
            {
                IQueryable <Pupils> a = repository.All();

                gv.DataSource = repository.All().Select(x => new EleveModels
                {
                    id           = x.Id,
                    firstName    = x.FirstName,
                    lastName     = x.LastName,
                    sexe         = x.Sex,
                    birthdayDate = x.BirthdayDate,
                    tuteurId     = x.Tutor_Id,
                    classroomId  = x.Classroom_Id,
                    levelId      = x.Level_Id
                }).ToList();
            }

            gv.DataBind();
            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename=Liste_élèves.xls");
            Response.ContentType = "application/ms-excel";
            Response.Charset     = "";
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            gv.RenderControl(htw);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();

            return(RedirectToAction("ReadEleves"));
        }
        public ActionResult EditEleve(EleveModels model)
        {
            using (EleveRepository repository = new EleveRepository())
            {
                Pupils x = repository.GetPupilById(model.id);
                x.State        = short.MaxValue;
                x.FirstName    = model.firstName;
                x.LastName     = model.lastName;
                x.Sex          = model.sexe;
                x.BirthdayDate = model.birthdayDate;
                x.Tutor_Id     = model.tuteurId;
                x.Classroom_Id = model.classroomId;
                x.Level_Id     = model.levelId;
                // eleves =

                if (ModelState.IsValid)
                {
                    repository.Save();
                }
                return(RedirectToAction("ReadEleves"));
            }
        }