public ActionResult SaisirResultats(Guid idEval)
        {
            ListeResultatsModels model = new ListeResultatsModels();

            using (EvaluationRepository repo = new EvaluationRepository())
            {
                Evaluations e = repo.GetEvaluationById(idEval);
                if (e == null)
                {
                    return(HttpNotFound());
                }
                IQueryable <Pupils> pupils = repo.GetPupilsByClassroom(repo.GetClassroomId(e));
                EvaluationModels    m      = new EvaluationModels
                {
                    id          = e.Id,
                    classroomId = e.Classroom_Id,
                    eleves      = getListPupils(pupils)
                };

                foreach (var eleve in m.eleves)
                {
                    ResultatModels r = new ResultatModels
                    {
                        pupilId      = eleve.id,
                        pupilName    = eleve.firstName + " " + eleve.lastName,
                        evaluationId = m.id
                    };
                    model.resultats.Add(r);
                }
            }
            model.mode = -1;
            return(View(model));
        }
 public ActionResult DeleteResultat(ResultatModels model)
 {
     using (ResultatRepository repository = new ResultatRepository())
     {
         repository.DeleteById(model.id);
         repository.Save();
     }
     return(View("Index"));
 }
        public ActionResult EditResultat(ResultatModels model)
        {
            using (ResultatRepository repository = new ResultatRepository())
            {
                Results x = repository.GetResultById(model.id);
                x.Evaluation_Id = model.evaluationId;
                x.Note          = model.note;
                x.Pupil_Id      = model.pupilId;

                if (ModelState.IsValid)
                {
                    repository.Save();
                }
                return(RedirectToAction("ReadResultats"));
            }
        }
        private List <ResultatModels> getListResultats(IQueryable <Results> resultats)
        {
            List <ResultatModels> r = new List <ResultatModels>();

            foreach (var res in resultats)
            {
                ResultatModels x = new ResultatModels
                {
                    id           = res.Id,
                    evaluationId = res.Evaluation_Id,
                    note         = res.Note,
                    pupilId      = res.Pupil_Id,
                };
                r.Add(x);
            }
            return(r);
        }
        // GET: /Eval/CreateResultat
        public ActionResult CreateResultat()
        {
            ResultatModels model;

            using (ResultatRepository repository = new ResultatRepository())
            {
                IQueryable <Evaluations> evaluations = repository.GetEvaluations();
                IQueryable <Pupils>      pupils      = repository.GetEleves();
                model = new ResultatModels
                {
                    mode        = -1,
                    eleves      = getListEleves(pupils),
                    evaluations = getListEvaluations(evaluations)
                };
            }
            return(View(model));
        }
        private List <ResultatModels> getListResultats(IQueryable <Results> results)
        {
            List <ResultatModels> l = new List <ResultatModels>();

            foreach (var r in results)
            {
                ResultatModels c = new ResultatModels
                {
                    evaluationId = r.Evaluation_Id,
                    id           = r.Id,
                    note         = r.Note,
                    pupilId      = r.Pupil_Id,
                    pupilName    = r.Pupils.FirstName + " " + r.Pupils.LastName
                };
                l.Add(c);
            }
            return(l);
        }
        public ActionResult CreateResultat(ResultatModels model)
        {
            if (ModelState.IsValid)
            {
                using (ResultatRepository repository = new ResultatRepository())
                {
                    Results a = new Results
                    {
                        Id            = Guid.NewGuid(),
                        Evaluation_Id = model.evaluationId,
                        Pupil_Id      = model.pupilId,
                        Note          = model.note
                    };

                    repository.Add(a);
                    repository.Save();
                }
                return(RedirectToAction("ReadEvaluations"));
            }
            return(View(model));
        }
        public ActionResult ReadResultat(Guid id)
        {
            ResultatModels model;

            using (ResultatRepository repository = new ResultatRepository())
            {
                Results x = repository.GetResultById(id);
                if (x == null)
                {
                    return(HttpNotFound());
                }
                model = new ResultatModels
                {
                    id           = x.Id,
                    evaluationId = x.Evaluation_Id,
                    note         = x.Note,
                    pupilId      = x.Pupil_Id
                };
            }
            return(View(model));
        }
        public ActionResult EditResultat(Guid id)
        {
            ResultatModels model;

            using (ResultatRepository repository = new ResultatRepository())
            {
                Results x = repository.GetResultById(id);
                IQueryable <Evaluations> evaluations = repository.GetEvaluations();
                IQueryable <Pupils>      pupils      = repository.GetEleves();
                if (x == null)
                {
                    return(HttpNotFound());
                }
                model = new ResultatModels
                {
                    mode         = 0,
                    id           = x.Id,
                    evaluationId = x.Evaluation_Id,
                    note         = x.Note,
                    pupilId      = x.Pupil_Id
                };
            }
            return(View("CreateResultat", model));
        }