public List<String> Faculties()
        {
            
            RankingContext context = new RankingContext();

            var f = from b in context.Faculties
                    select b.FacultyName;

            return f.ToList<String>();
        }
        public List<String> Programmes(String facultyName)
        {
            
            RankingContext context = new RankingContext();

            var f = from b in context.Faculties
                    where b.FacultyName == facultyName
                    select b.ProgrammeName;

            return f.ToList<String>();
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            String user = model.UserName;
            String pass = model.Password;

            if ( ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)
                 && model.UserName == "Admin" )
            {
                RankingContext db = new RankingContext();

                if (db.Dates.ToList().Count() == 0)
                {
                    return RedirectToAction("index", "CampaignRankingDates");
                }
                return RedirectToAction("Menu", "Admin");
            }
            


            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)
                  )
            {
                string name = model.UserName;
                string[] roleNames = Roles.GetRolesForUser(name);
                foreach (string role in roleNames)
               {
                   if (role.Contains("admin"))
                   {
                       return RedirectToAction("Menu", "Admin");      
                   }
               }
            }

            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                RankingContext db = new RankingContext();
                QueryManager mng = new QueryManager(db);
                DateTime end = Convert.ToDateTime(mng.getCampaignDates().FirstRankingDate);
                if (DateTime.Today > end)
                {
                    return RedirectToAction("Index", "StudentRankingInformation");
                }

                //return RedirectToLocal(returnUrl);
               return  RedirectToAction("Index", "StudentPreferences");
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
 public QueryManager(RankingContext context)
 {
     this.context = context;
 }
Esempio n. 5
0
 public Ranker(RankingContext context)
 {
     this.context = context;
     queryManager = new QueryManager(context);
 }
        public ActionResult Index()
        {
            String user = User.Identity.Name;
            //user = "******";
            ViewData["userName"] = user;

            List<String> l = programmes.Keys.ToList<string>();
            l.Insert(0,"Please Select");
            SelectList faculties = new SelectList(l);
       
            ViewData["faculties"] = faculties;

            RankingContext db = new RankingContext();
            QueryManager mng = new QueryManager(db);

            DateTime end = Convert.ToDateTime(mng.getCampaignDates().PreferrencesLastDate);
            ViewData["isAddingPreferencesEnd"] = false;
            if (DateTime.Today > end)
            {
                ViewData["isAddingPreferencesEnd"] = true;
            }



            QueryManager queryManager = new QueryManager(db);

            List<Preference> studentPreferences = queryManager.getStudentPreferences(user);

            foreach (var preff in studentPreferences)
            {
                Faculty f = db.Faculties.Find(preff.ProgrammeName);
                String fac = (f != null ) ? f.FacultyName : "";
                StudentPreferences pr = new StudentPreferences
                {
                    Faculty = fac,
                    ProgrammeName = preff.ProgrammeName,
                    PrefNumber = preff.PrefNumber
                };
                model.Add(pr);
            }
            ViewData["result"] = model;

            return View(model);
        }
        public ActionResult Index(String faculty, String programmeName)
        {
            String user = User.Identity.Name;
            ViewData["userName"] = user;


            RankingContext db = new RankingContext();
            QueryManager mng = new QueryManager(db);

            DateTime finale = Convert.ToDateTime(mng.getCampaignDates().PreferrencesLastDate); 
            

            ViewData["isAddingPreferencesEnd"] = true;

            if (DateTime.Today > finale)
            {
                ViewData["isAddingPreferencesEnd"] = true;
            }


            List<String> l = programmes.Keys.ToList<string>();
            l.Insert(0, "Please Select");
            SelectList faculties = new SelectList(l);

            ViewData["faculties"] = faculties;

            

            String egn = user;

            //int lastPreferenceNumber = db.Preferences.Where(t => t.EGN == egn )
            //                                         .OrderByDescending(t => t.PrefNumber)
            //                                         .FirstOrDefault().PrefNumber;

            QueryManager queryManager = new QueryManager(db);

            List<Preference> studentPreferences = queryManager.getStudentPreferences(egn);

            bool isPreferrenceRepeated = false;
            foreach (var preff in studentPreferences)
            {
                String fac = db.Faculties.Find(preff.ProgrammeName).FacultyName;
                StudentPreferences pr = new StudentPreferences { Faculty = fac, ProgrammeName = preff.ProgrammeName,
                                                                 PrefNumber = preff.PrefNumber };
                if (faculty == fac && preff.ProgrammeName == programmeName)
                {
                    isPreferrenceRepeated = true;
                }

                model.Add(pr);
            }

            
           
            if (!isPreferrenceRepeated)
            {
                int nextPrefenceNumber = (studentPreferences.Count() != 0) ? studentPreferences.Max(t => t.PrefNumber) + 1 : 1;
                StudentPreferences pref = new StudentPreferences
                {
                    Faculty = faculty,
                    ProgrammeName = programmeName,
                    PrefNumber = nextPrefenceNumber
                };
                Preference p = new Preference
                {
                    EGN = egn,
                    PrefNumber = nextPrefenceNumber,
                    ProgrammeName = programmeName,
                    TotalGrade = 0
                };

                db.Preferences.Add(p);
                db.SaveChanges();
                model.Add(pref);
            }
            
            ViewData["result"] = model;



            return PartialView("_StudentPreferencesTable", model);
            //return View("Index",model);
        }
        public ActionResult Index()
        {

            RankingContext db = new RankingContext();
            QueryManager mng = new QueryManager(db);

            



            String user = User.Identity.Name;

            String s = mng.getCampaignDates().FirstRankingDate;
            // класиране първи етап - дати
            DateTime first = Convert.ToDateTime(mng.getCampaignDates().FirstRankingDate);
            ViewData["isFirstRankingDate"] = false;
            if (DateTime.Today >= first)
            {
                ViewData["isFirstRankingDate"] = true;
            }

            ViewData["isFirstRankListPublished"] = false;
            if (db.Dates.ToList().Last().FirstRankingDate == "true")
            {
                ViewData["isFirstRankListPublished"] = true;
            }


            // класиране втори етап - дати
            DateTime second = Convert.ToDateTime(mng.getCampaignDates().SecondRankingDate);
            ViewData["isSecondRankingDate"] = false;
            if (DateTime.Today >= second)
            {
                ViewData["isSecondRankingDate"] = true;
            }

            ViewData["isSecondRankListPublished"] = false;
            if (db.Dates.ToList().Last().FirstRankingDate == "true")
            {
                ViewData["isSecondRankListPublished"] = true;
            }

            // класиране трети етап - дати
            DateTime third = Convert.ToDateTime(mng.getCampaignDates().ThirdRankingDate);
            ViewData["isThirdRankingDate"] = false;
            if (DateTime.Today >= third)
            {
                ViewData["isThirdRankingDate"] = true;
            }

            ViewData["isThirdRankListPublished"] = false;
            if (db.Dates.ToList().Last().FirstRankingDate == "true")
            {
                ViewData["isThirdRankListPublished"] = true;
            }



            ViewData["mainAdmin"] = false;
            if (user == "Admin")
            {
                ViewData["mainAdmin"] = true;
            }

            ViewData["userName"] = user;



            List<String> l = programmes.Keys.ToList<string>();
            l.Insert(0, "Please Select");
            SelectList faculties = new SelectList(l);

            ViewData["faculties"] = faculties;

            ViewData["result"] = model;

            return View(model);
        }
        public ActionResult Index(String faculty, String programmeName)
        {
            //генериране на combobox
            List<String> l = programmes.Keys.ToList<string>();
            l.Insert(0, "Please Select");
            SelectList faculties = new SelectList(l);
            ViewData["faculties"] = faculties;
            
            //проверка дали е настъпила дата за обявяване на класиране

            RankingContext db = new RankingContext();
            QueryManager mng = new QueryManager(db);

            // класиране първи етап - дати
            DateTime first = Convert.ToDateTime(mng.getCampaignDates().FirstRankingDate);
            ViewData["isFirstRankingDate"] = false;
            if (DateTime.Today >= first)
            {
                ViewData["isFirstRankingDate"] = true;
            }

            ViewData["isFirstRankListPublished"] = false;
            if (db.Dates.ToList().Last().FirstRankingDate == "true")
            {
                ViewData["isFirstRankListPublished"] = true;
            }


            // класиране втори етап - дати
            DateTime second = Convert.ToDateTime(mng.getCampaignDates().SecondRankingDate);
            ViewData["isSecondRankingDate"] = false;
            if (DateTime.Today >= second)
            {
                ViewData["isSecondRankingDate"] = true;
            }

            ViewData["isSecondRankListPublished"] = false;
            if (db.Dates.ToList().Last().FirstRankingDate == "true")
            {
                ViewData["isSecondRankListPublished"] = true;
            }

            // класиране трети етап - дати
            DateTime third = Convert.ToDateTime(mng.getCampaignDates().ThirdRankingDate);
            ViewData["isThirdRankingDate"] = false;
            if (DateTime.Today >= third)
            {
                ViewData["isThirdRankingDate"] = true;
            }

            ViewData["isThirdRankListPublished"] = false;
            if (db.Dates.ToList().Last().FirstRankingDate == "true")
            {
                ViewData["isThirdRankListPublished"] = true;
            }



            //вземане на потребителското име на потребителя
            String user = User.Identity.Name;
            ViewData["userName"] = user;

            //проверка кой администратор е влязъл
            ViewData["mainAdmin"] = false;
            if (user == "Admin")
            {
                ViewData["mainAdmin"] = true;
            }

            QueryManager queryManager = new QueryManager(db);

            List<FacultyRankList> rankList = queryManager.getRankList(programmeName);

            foreach (var item in rankList)
            {
                FacultyRankList rank = new FacultyRankList
                {
                    ProgrammeName = programmeName,
                    EGN = item.EGN,
                    TotalGrade = item.TotalGrade
                };
                model.Add(rank);
            }

            //FacultyRankList f = new FacultyRankList
            //{
            //    EGN = "12345678",
            //    ProgrammeName = programmeName,
            //    TotalGrade = 4.5
            //};
            //model.Add(f);

            ViewData["result"] = model;
            
            return PartialView("_ProgrammeRankListTable", model);
        }