Пример #1
0
        /// <summary>
        /// Converti une liste d'entités <see cref="Eleve"/> en liste de ViewModel <see cref="EleveViewModel"/>
        /// </summary>
        /// <param name="notes">Liste d'entités <see cref="Eleve"/></param>
        /// <returns>Liste d'objets ViewModel <see cref="EleveViewModel"/></returns>
        public List <EleveViewModel> ConvertToViewModels(List <Eleve> eleves)
        {
            AbsenceAdapter absenceAdapter = new AbsenceAdapter();
            NoteAdapter    noteAdapter    = new NoteAdapter();

            var vms = new List <EleveViewModel>();

            if (eleves == null)
            {
                return(vms);
            }

            foreach (Eleve eleve in eleves)
            {
                var vm = new EleveViewModel
                {
                    EleveId       = eleve.EleveId,
                    Nom           = eleve.Nom,
                    Prenom        = eleve.Prenom,
                    DateNaissance = eleve.DateNaissance,
                    ClassId       = eleve.ClassId,
                    Notes         = noteAdapter.ConvertToViewModels(eleve.Notes.ToList())
                };

                if (vm.Notes != null)
                {
                    vm.Moyenne = vm.Notes.Average(n => n.ValeurNote);
                }

                vms.Add(vm);
            }

            return(vms);
        }
Пример #2
0
        /// <summary>
        /// Converti une entité <see cref="Eleve"/> en ViewModel <see cref="EleveViewModel"/>
        /// </summary>
        /// <param name="note">Entité <see cref="Eleve"/></param>
        /// <returns>Objet ViewModel <see cref="EleveViewModel"/></returns>
        public EleveViewModel ConvertToViewModel(Eleve eleve)
        {
            AbsenceAdapter absenceAdapter = new AbsenceAdapter();
            NoteAdapter    noteAdapter    = new NoteAdapter();

            if (eleve == null)
            {
                return(null);
            }

            var vm = new EleveViewModel
            {
                EleveId       = eleve.EleveId,
                Nom           = eleve.Nom,
                Prenom        = eleve.Prenom,
                DateNaissance = eleve.DateNaissance,
                ClassId       = eleve.ClassId,
                Absences      = absenceAdapter.ConvertToViewModels(eleve.Absences.ToList()),
                Notes         = noteAdapter.ConvertToViewModels(eleve.Notes.ToList())
            };

            if (vm.Notes != null)
            {
                vm.Moyenne = vm.Notes.Average(n => n.ValeurNote);
            }

            return(vm);
        }