Beispiel #1
0
        // GET: Message
        public ActionResult Index(int?pageIndex, int?pageSize)
        {
            if (pageIndex == null)
            {
                pageIndex = 1;
            }
            if (pageSize == null)
            {
                pageSize = 10;
            }
            if (Session["user"] is Etudiant)
            {
                var            user     = (Etudiant)Session["user"];
                List <Message> messages = _messageService.GetMessagesBySpecialiteAndNiveau(user.SpecialiteId, user.Niveau, (int)pageIndex, (int)pageSize).ToList();
                ViewBag.professeurs = _professeurService.GetProfesseursBySpecialiteAndNiveau(user.SpecialiteId, user.Niveau);
                ViewBag.maxPage     = (int)Math.Ceiling(_messageService.GetAll().Where(o => o.SpecialiteId == user.SpecialiteId && o.Niveau == user.Niveau).Count() / (decimal)pageSize);
                ViewBag.pageIndex   = (int)pageIndex;
                return(View(messages));
            }
            else if (Session["user"] is Professeur)
            {
                var            user     = (Professeur)Session["user"];
                List <Message> messages = _messageService.GetMessagesByProfesseur(user.ProfesseurId, (int)pageIndex, (int)pageSize).ToList();
                List <ProfesseurSpecialite>      professeurSpecialites = _professeurSpecialiteService.GetSpecialitesByProfesseur(user.ProfesseurId).ToList();
                Dictionary <string, List <int> > niveauBySpecialite    = new Dictionary <string, List <int> >();
                List <Specialite>       specialites       = new List <Specialite>();
                List <ProfesseurModule> professeurModules = _professeurModuleService.GetModulesByProfesseur(user.ProfesseurId).ToList();

                foreach (ProfesseurSpecialite p in professeurSpecialites)
                {
                    bool       uTeach          = false;
                    List <int> niveau          = new List <int>();
                    List <SpecialiteModule> sm = _specialiteModuleService.GetSpecialiteModulesBySpecialite(p.SpecialiteId).ToList();
                    specialites.Add(_specialiteService.Get(p.SpecialiteId));
                    foreach (ProfesseurModule m in professeurModules)
                    {
                        foreach (SpecialiteModule s in sm)
                        {
                            if (s.ModuleId == m.ModuleId)
                            {
                                uTeach = true;
                                niveau.Add(_specialiteModuleService.GetNiveauBySpecialiteAndModule(p.SpecialiteId, s.ModuleId));
                            }
                        }
                    }
                    if (uTeach)
                    {
                        niveauBySpecialite.Add(p.SpecialiteId.ToString(), niveau);
                    }
                }
                ViewBag.specialites        = specialites;
                ViewBag.niveauBySpecialite = JsonConvert.SerializeObject(niveauBySpecialite, Formatting.Indented);

                return(View(messages));
            }
            return(null);
        }
        public ActionResult Officiel(int?pageIndex, int?pageSize)
        {
            if (pageIndex == null || pageIndex < 1)
            {
                pageIndex = 1;
            }
            if (pageSize == null || pageSize < 1)
            {
                pageSize = 10;
            }
            if (Session["user"] is Etudiant)
            {
                var user = (Etudiant)Session["user"];
                List <DocumentOfficiel> documents = _documentOfficielService.GetAll().OrderByDescending(o => o.DocumentOfficielId).Skip(((int)pageIndex - 1) * (int)pageSize).Take((int)pageSize).ToList();
                ViewBag.professeurs = _professeurService.GetProfesseursBySpecialiteAndNiveau(user.SpecialiteId, user.Niveau);
                ViewBag.pageIndex   = (int)pageIndex;
                ViewBag.TopUsers    = _documentOfficielService.GetTopUsers(_professeurService.GetProfesseursBySpecialiteAndNiveau(((Etudiant)Session["user"]).SpecialiteId, ((Etudiant)Session["user"]).Niveau).Values.ToList());
                return(View(documents));
            }
            else if (Session["user"] is Professeur)
            {
                var user = (Professeur)Session["user"];
                List <ProfesseurSpecialite> professeurSpecialites = _professeurSpecialiteService.GetSpecialitesByProfesseur(user.ProfesseurId).ToList();
                List <Specialite>           specialites           = new List <Specialite>();
                List <ProfesseurModule>     professeurModules     = _professeurModuleService.GetModulesByProfesseur(user.ProfesseurId).ToList();
                List <Module> modules = new List <Module>();
                foreach (ProfesseurSpecialite specialite in professeurSpecialites)
                {
                    specialites.Add(_specialiteService.Get(specialite.SpecialiteId));
                }
                foreach (ProfesseurModule professeurModule in professeurModules)
                {
                    modules.Add(_moduleService.Get(professeurModule.ModuleId));
                }

                List <DocumentOfficiel> documents = _documentOfficielService.GetDocumentsByUser(user.ProfesseurId, (int)pageIndex, (int)pageSize).ToList();
                ViewBag.modules     = modules;
                ViewBag.specialites = specialites;
                ViewBag.pageIndex   = (int)pageIndex;
                ViewBag.maxPage     = (int)Math.Ceiling(_documentOfficielService.GetAll().Where(o => o.ProfesseurId == user.ProfesseurId).Count() / (decimal)pageSize);
                return(View(documents));
            }
            else
            {
            }

            return(null);
        }
        public ActionResult AddResultats(HttpPostedFileBase resultat, int specialite, string semester, string year)
        {
            Administrateur user = (Administrateur)Session["user"];

            if (resultat != null && resultat.ContentLength > 0)
            {
                var extension = Path.GetExtension(resultat.FileName);
                if (!extension.ToLower().Equals(".pdf"))
                {
                    return(RedirectToAction("UserProfile"));
                }
                var      path   = "~/Resources/Resultats/" + "Resultats_" + _specialiteService.Get(specialite).Abreviation + "_" + semester + "_" + year.Substring(0, 4) + "_" + year.Substring(5, 4) + extension.ToLower();
                Resultat result = new Resultat
                {
                    AdministrateurId = user.AdministrateurId,
                    Annee            = year,
                    Path             = path,
                    Semestre         = byte.Parse(semester.Last().ToString()),
                    SpecialiteId     = specialite
                };
                result = _resultatService.Add(result);
                if (result != null)
                {
                    resultat.SaveAs(Path.Combine(Server.MapPath("~/Resources/Resultats"), "Resultats_" + _specialiteService.Get(specialite).Abreviation + "_" + semester + "_" + year.Substring(0, 4) + "_" + year.Substring(5, 4) + extension.ToLower()));
                    return(RedirectToAction("Index", "Annonce"));
                }
            }
            return(RedirectToAction("AddAvis", "Administrateur"));
        }
        // GET: Professeur
        public ActionResult Index()
        {
            Professeur user = (Professeur)Session["user"];
            // Notifications
            List <Notification> notifications = _notificationService.GetUnreadNotifications(user.ProfesseurId).ToList();
            int             notificationCount = notifications.Count();
            List <Etudiant> etudiants         = new List <Etudiant>();
            // Documents
            List <DocumentOfficiel>    mesDocuments   = _documentOfficielService.GetDocumentsByUser(user.ProfesseurId, 1, 10).ToList();
            List <DocumentNonOfficiel> documents      = new List <DocumentNonOfficiel>();
            List <Module>           modules           = new List <Module>();
            List <ProfesseurModule> professeurModules = _professeurModuleService.GetModulesByProfesseur(user.ProfesseurId).ToList();

            foreach (ProfesseurModule module in professeurModules)
            {
                modules.Add(_moduleService.Get(module.ModuleId));
                documents.AddRange(_documentNonOfficielService.GetDocumentByModule(module.ModuleId));
            }

            documents = documents.OrderByDescending(o => o.DocumentNonOfficielId).Take(10).ToList();
            // Messages
            List <Message> messages = _messageService.GetMessagesByProfesseur(user.ProfesseurId, 1, 5).ToList();
            // Specialites
            List <Specialite> specialites = new List <Specialite>();
            // Annonces
            List <Annonce> annonces = _annonceService.GetAll().OrderByDescending(o => o.AnnonceId).Take(5).ToList();

            //Etudiants
            var specialiteWithNiveau = _professeurService.GetSpecialiteWithNiveau(user.ProfesseurId);

            foreach (int specialite in specialiteWithNiveau.Keys)
            {
                specialites.Add(_specialiteService.Get(specialite));
                foreach (int niveau in specialiteWithNiveau[specialite])
                {
                    etudiants.AddRange(_etudiantService.GetEtudiantsBySpecialite(specialite, niveau).ToList());
                }
            }

            // Model
            Session["notifications"]     = notifications;
            Session["notificationCount"] = notificationCount;
            ViewBag.documents            = documents;
            ViewBag.messages             = messages;
            ViewBag.annonces             = annonces;
            ViewBag.specialites          = specialites;
            ViewBag.modules   = modules;
            ViewBag.etudiants = etudiants;
            return(View(mesDocuments));
        }
Beispiel #5
0
        public ActionResult Login(string login, string password)
        {
            Administrateur admin = _administrateurService.GetUserByAuth(login, password);

            if (admin != null)
            {
                Session["user"] = admin;
                // Notifications
                List <Notification> notifications = _notificationService.GetUnreadNotifications(admin.AdministrateurId).ToList();
                int notificationCount             = notifications.Count();
                Session["notifications"]     = notifications;
                Session["notificationCount"] = notificationCount;

                return(RedirectToAction("index", "Administrateur"));
            }
            else
            {
                var prof = _professeurService.GetUserByAuth(login, password);
                if (prof != null)
                {
                    Session["user"] = prof;
                    // Notifications
                    List <Notification> notifications = _notificationService.GetUnreadNotifications(prof.ProfesseurId).ToList();
                    int notificationCount             = notifications.Count();
                    Session["notifications"]     = notifications;
                    Session["notificationCount"] = notificationCount;
                    return(RedirectToAction("Index", "Professeur"));
                }
                else
                {
                    var etudiant = _etudiantService.GetUserByAuth(login, password);
                    if (etudiant != null)
                    {
                        Session["user"] = etudiant;
                        List <Notification> notifications = _notificationService.GetUnreadNotifications(etudiant.EtudiantId).ToList();
                        int notificationCount             = notifications.Count();
                        Session["notifications"]     = notifications;
                        Session["notificationCount"] = notificationCount;
                        Session["specialite"]        = _specialiteService.Get(etudiant.SpecialiteId).Designation;
                        return(RedirectToAction("Index", "Etudiant"));
                    }
                }
            }


            return(View("Index"));
        }