예제 #1
0
        public ApercuPlanCours GetUser(int id)
        {
            var apercu = new ApercuPlanCours();
            var query  = from user in _db.PlanCoursUtilisateur
                         where user.IdPlanCours == id
                         select user;

            if (!query.Any())
            {
                return(null);
            }
            var planCoursUser = query.First();
            var utilisateur   = HttpContext.GetOwinContext()
                                .GetUserManager <ApplicationUserManager>()
                                .FindById(planCoursUser.IdPlanCoursUtilisateur);
            var bureauProf   = planCoursUser.BureauProf;
            var noPoste      = planCoursUser.Poste;
            var courrielProf = utilisateur.Email;
            var nomProf      = utilisateur.nom;
            var prenomProf   = utilisateur.prenom;


            apercu.CreatePageTitre(nomProf, prenomProf, bureauProf, noPoste, courrielProf);
            return(apercu);
        }
 public ActionResult Create(ApercuViewModel ApercuViewModel, FormCollection collection)
 {
     try {
         string    UserId    = User.Identity.GetUserId();
         PlanCadre planCadre = _db.PlanCadre.Find(ApercuViewModel.IdPlanCadre);
         var       Cours     = from cours in _db.Cours
                               where cours.IdPlanCadre == ApercuViewModel.IdPlanCadre
                               select cours;
         int CoursId = Cours.First().IdCours;
         Models.Plan_Cours.PlanCours PC = new Models.Plan_Cours.PlanCours()
         {
             DateCreation    = DateTime.Today,
             DateValidation  = null,
             IdCours         = CoursId,
             StatutPlanCours = false,
         };
         _db.PlanCours.Add(PC);
         _db.SaveChanges();
         var idPlanCours = PC.IdPlanCours;
         var PCU         = new PlanCoursUtilisateur()
         {
             IdPlanCoursUtilisateur = UserId,
             IdPlanCours            = idPlanCours,
             BureauProf             = ApercuViewModel.BureauProf,
             Poste = ApercuViewModel.NoPoste,
         };
         _db.PlanCoursUtilisateur.Add(PCU);
         _db.SaveChanges();
         _apercu = GetUser(idPlanCours);
         for (var i = 1; i < 15; i++)
         {
             var texteSectionDefault = new TexteSection {
                 IdPlanCours = idPlanCours, IdContenuSection = i
             };
             _db.TexteSection.Add(texteSectionDefault);
             _db.SaveChanges();
         }
         return(RedirectToAction("Index", new
         {
             apercu = _apercu,
             id = PC.IdPlanCours,
         }));
     }
     catch
     {
         return(View());
     }
 }
예제 #3
0
        public ActionResult Index(ApercuPlanCours apercu, int?id)
        {
            viewModel = new ApercuViewModel();
            var courrielConnexion = User.Identity.Name;
            var requete           = from acces in _db.AccesProgramme
                                    where acces.UserMail == courrielConnexion
                                    select acces.Discipline;
            var listePlanCours = new List <Models.Plan_Cours.PlanCours>();

            foreach (var planCoursId in GetPlanCours())
            {
                listePlanCours.Add(_db.PlanCours.Find(planCoursId));
            }
            foreach (var planCours in listePlanCours)
            {
                var nomSection = from nomS in _db.NomSection
                                 join cs in _db.ContenuSection on nomS.IdNomSection equals cs.IdNomSection
                                 join ts in _db.TexteSection on cs.IdContenuSection equals ts.IdContenuSection
                                 join pco in _db.PlanCours on ts.IdPlanCours equals pco.IdPlanCours
                                 where pco.IdPlanCours == planCours.IdPlanCours
                                 select nomS;

                viewModel.MainPageViewModel.NomSections = new List <List <NomSection> >
                {
                    new List <NomSection> {
                        nomSection as NomSection
                    }
                };
            }

            if (id == null)
            {
                id = 1;
            }
            var idPlanCadre = from planCours in _db.PlanCours
                              join cours in _db.Cours on planCours.IdCours equals cours.IdCours
                              join planCadre in _db.PlanCadre on cours.IdPlanCadre equals planCadre.IdPlanCadre
                              where planCours.IdPlanCours == id
                              select planCadre.IdPlanCadre;

            viewModel.MainPageViewModel.PlanCours      = listePlanCours;
            viewModel.MainPageViewModel.ContenuSection = _db.ContenuSection.ToList();
            viewModel.MainPageViewModel.NomSection     = _db.NomSection.ToList();
            apercu = GetUser(Convert.ToInt32(id));
            if (apercu != null)
            {
                List <PlanCoursDepart> pcd = new List <PlanCoursDepart>();
                ViewBag.courrielProf   = apercu.CourrielProf;
                ViewBag.imageCegep     = VirtualPathUtility.ToAbsolute(apercu.ImageCegep);
                ViewBag.imageDepart    = VirtualPathUtility.ToAbsolute(apercu.ImageDepart);
                ViewBag.phrase         = apercu.Phrase;
                ViewBag.infosCours     = CreationInfoCours(Convert.ToInt32(idPlanCadre.First()));
                ViewBag.infosProf      = apercu.InfosProf;
                ViewBag.LocalProf      = apercu.LocalProf;
                ViewBag.session        = apercu.Session;
                viewModel.TexteContenu = new string[15];
                viewModel.TitreSection = new string[15];
                var listeSection = RetourneSection(requete.First(), Convert.ToInt32(id));
                viewModel.IndexSection = listeSection;
                foreach (var section in listeSection)
                {
                    try
                    {
                        var texte = CreationSectionDepart(Convert.ToInt32(id), section, requete.First());
                        viewModel.TexteContenu[section] = texte;
                        var titre = CreationTitreSection(Convert.ToInt32(id), section);
                        viewModel.TitreSection[section] = titre;
                    }
                    catch (Exception)
                    {
                        var textecontenu = CreationSectionDefaut(Convert.ToInt32(id), section, requete.First());
                        viewModel.TexteContenu[section] = textecontenu;
                        var titreSection = CreationTitreSection(Convert.ToInt32(id), section);
                        viewModel.TitreSection[section] = titreSection;
                    }
                }

                CreationEnonceCompetence(viewModel, (int)id);
            }
            else
            {
                this.AddToastMessage("Attention", "Aucun plan cours n'est associé à votre compte", ToastType.Warning);
            }

            return(View(viewModel));
        }