Example #1
0
        public ActionResult EnrollStudent(String programmeName)
        {
            String user = User.Identity.Name;

            ViewData["userName"] = user;
            Student st = db.Students.Find(user);

            st.IsEnrolled = true;

            db.Entry(st).State = EntityState.Modified;
            db.SaveChanges();
            ViewData["isEnrolled"] = true;

            QueryManager           manager  = new QueryManager(db);
            List <FacultyRankList> rankList = manager.getStudentRankList(user);

            foreach (var item in rankList)
            {
                if (item.ProgrammeName != programmeName)
                {
                    db.FacultyRankLists.Attach(item);
                    db.FacultyRankLists.Remove(item);
                    db.SaveChanges();
                }
            }


            //return RedirectToAction("Index", "StudentRankingInformation");
            var redirectUrl = new UrlHelper(Request.RequestContext).Action("Index", "StudentRankingInformation");

            return(Json(new { Url = redirectUrl }));
        }
        private Athlete CreateAthlete()
        {
            var athlete = new Athlete
            {
                Name      = "Raul",
                BirthYear = 1990,
                Genre     = Genre.Male
            };

            unit.Athletes.Add(athlete);
            unit.SaveChanges();

            return(unit.Athletes.First());
        }
Example #3
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            if (NothingSelected())
            {
                return;
            }
            var athleteId = GetAthleteId();
            var athlete   = _context.Athletes.Find(athleteId);

            if (athlete == null)
            {
                Commons.Message.Error($"No he trobat l'atleta", "");
            }

            var result = Commons.Message.Question($"Desitja esborrar l'atleta\n{athlete.Name}", "Esborrar atleta");

            if (result == DialogResult.Yes)
            {
                try
                {
                    _context.Athletes.Remove(athlete);
                    _context.SaveChanges();

                    ShowGrid(GetAllAthletes());
                    Commons.Message.Information("Atleta esborrat !!", "");
                }
                catch (Exception error)
                {
                    Commons.Message.Error(error.Message, "Error");
                }
            }
        }
Example #4
0
        private bool SaveData()
        {
            var item = ScreenToClassMap();

            var athlete = _context.Athletes.Find(_athleteId);

            if (athlete == null)
            {
                athlete = new Athlete();
            }
            else
            {
                athlete.Id = _athleteId;
            }

            athlete.BirthYear = item.BirthYear;
            athlete.Genre     = item.Genre;
            athlete.Name      = item.Name;

            if (_athleteId == 0)
            {
                _context.Athletes.Add(athlete);
            }

            var regs = _context.SaveChanges();

            return(regs > 0);
        }
Example #5
0
        private bool SaveData()
        {
            var item = ScreenToClassMap();

            var trial = _context.Trials.Find(_Id);

            if (trial == null)
            {
                trial = new Trial();
            }
            else
            {
                trial.Id = _Id;
            }

            trial.Measurement      = item.Measurement;
            trial.Name             = item.Name;
            trial.QuantityAthletes = item.QuantityAthletes;

            if (_Id == 0)
            {
                _context.Trials.Add(trial);
            }
            var regs = _context.SaveChanges();

            return(regs > 0);
        }
Example #6
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            if (NothingSelected())
            {
                return;
            }
            var id   = GetId();
            var item = _context.Marks.Find(id);

            if (item == null)
            {
                Commons.Message.Error($"No he trobat la marca", "");
            }

            var result = Commons.Message.Question($"Desitja esborrar la marca?", "Esborrar marca");

            if (result == DialogResult.Yes)
            {
                try
                {
                    _context.Marks.Remove(item);
                    _context.SaveChanges();

                    ShowGrid(GetAllMarks());
                    Commons.Message.Information("Marca esborrada !!", "");
                }
                catch (Exception error)
                {
                    Commons.Message.Error(error.Message, "Error");
                }
            }
        }
        public ActionResult Create(Exam exam)
        {
            var examsNames = from exam2 in db.ExamNames
                             select exam2.Name;


            ViewData["currentExamName"] = new SelectList(examsNames.ToList());

            if (ModelState.IsValid)
            {
                db.Exams.Add(exam);
                db.SaveChanges();
                return(RedirectToAction("Create", "Exam"));
            }

            return(View(exam));
        }
        public ActionResult Index(CampaignRankingDates ranking)
        {
            RankingDates dates = new RankingDates
            {
                FirstRankingDate      = ranking.FirstRankingDate.ToString(),
                PreferrencesFirstDate = ranking.StudentPreferenceFirstDate.ToString(),
                PreferrencesLastDate  = ranking.StudentPreferenceLastDate.ToString(),
                SecondRankingDate     = ranking.SecondRankingDate.ToString(),
                ThirdRankingDate      = ranking.ThirdRankingDate.ToString()
            };

            RankingDates d = new RankingDates
            {
                FirstRankingDate      = "false",
                PreferrencesFirstDate = "false",
                PreferrencesLastDate  = "false",
                SecondRankingDate     = "false",
                ThirdRankingDate      = "false"
            };

            if (db.Dates.ToList().Count() != 0)
            {
                RankingDates p = db.Dates.ToList().First();
                RankingDates q = db.Dates.ToList().Last();

                db.Dates.Attach(p);
                db.Dates.Remove(p);
                db.SaveChanges();

                db.Dates.Attach(q);
                db.Dates.Remove(q);
                db.SaveChanges();
            }


            db.Dates.Add(dates);
            db.SaveChanges();

            db.Dates.Add(d);
            db.SaveChanges();

            return(RedirectToAction("Menu", "Admin"));
        }
Example #9
0
        public ActionResult algoStart()
        {
            //Algo start
            Ranker ranker = new Ranker(db);

            ranker.start();

            RankingDates dates = db.Dates.ToList().Last();


            if (dates.FirstRankingDate == "false")
            {
                dates.FirstRankingDate = "true";
                db.Entry(dates).State  = EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                if (dates.FirstRankingDate == "true" && dates.SecondRankingDate == "false")
                {
                    dates.SecondRankingDate = "true";
                    db.Entry(dates).State   = EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    if (dates.SecondRankingDate == "true" && dates.ThirdRankingDate == "false")
                    {
                        dates.ThirdRankingDate = "true";
                        db.Entry(dates).State  = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
            }


            //return RedirectToAction("Index", "StudentRankingInformation");
            var redirectUrl = new UrlHelper(Request.RequestContext).Action("Index", "ProgrammeRankList");

            return(Json(new { Url = redirectUrl }));
        }
        public void SaveCounts(int maleCount, int femaleCount, string programmeName)
        {
            //ako crashnat int-ovete napravi si go sys string parametri
            var rule = db.ProgrammesRules.Find(programmeName);

            if (rule == null)
            {
                db.ProgrammesRules.Add(new ProgrammeRules()
                {
                    FemaleCount   = femaleCount,
                    MaleCount     = maleCount,
                    ProgrammeName = programmeName
                });
                db.SaveChanges();
                return;
            }
            rule.MaleCount       = maleCount;
            rule.FemaleCount     = femaleCount;
            db.Entry(rule).State = EntityState.Modified;
            db.SaveChanges();
        }
Example #11
0
        private bool SaveData()
        {
            if (currentMark.Id == 0)
            {
                _context.Marks.Add(currentMark);
            }
            else
            {
                _context.Entry(currentMark).State = System.Data.Entity.EntityState.Modified;
            }

            _context.SaveChanges();
            return(true);
        }
Example #12
0
        public void grade(String studentEGN, List <Preference> preferences)
        {
            grades = queryManager.getStudentGrades(studentEGN);

            //TODO: Should we check for exams with the same name but different date?

            foreach (Preference preference in preferences)
            {
                preference.TotalGrade = calculateTotalGrade(studentEGN, preference.ProgrammeName);

                //add total grade in preference table
                context.Preferences.Attach(preference);
                context.Entry(preference).Property(x => x.TotalGrade).IsModified = true;
                context.SaveChanges();
            }
        }
        public ActionResult deleteLastPreference()
        {
            QueryManager queryManager = new QueryManager(db);

            List <Preference> studentPreferences = queryManager.getStudentPreferences(User.Identity.Name);

            if (studentPreferences.Count() > 0)
            {
                Preference p = studentPreferences.Last();
                db.Preferences.Attach(p);
                db.Preferences.Remove(p);
                db.SaveChanges();
            }

            var redirectUrl = new UrlHelper(Request.RequestContext).Action("Index", "StudentPreferences");

            return(Json(new { Url = redirectUrl }));
        }
Example #14
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            if (NothingSelected())
            {
                return;
            }

            var id   = GetId();
            var item = _context.Trials.Find(id);

            if (item == null)
            {
                Commons.Message.Error($"No he trobat la prova", "");
            }

            if ((item.Marks?.Count ?? 0) > 0)
            {
                Commons.Message.Error($"Aquesta prova s'está fent servir a {item.Marks.Count} marques", "Esborrar prova");
                return;
            }

            var result = Commons.Message.Question($"Desitja esborrar la prova\n{item.Name}", "Esborrar prova");

            if (result == DialogResult.Yes)
            {
                try
                {
                    _context.Trials.Remove(item);
                    _context.SaveChanges();

                    ShowGrid(GetAllTrials());
                    Commons.Message.Information("Prova esborrada !!", "");
                }
                catch (Exception error)
                {
                    Commons.Message.Error(error.Message, "Error");
                }
            }
        }
Example #15
0
        public TeamStat GetOrCreateByTeam(int teamId)
        {
            var teamStat = _ctx.TeamStats.AsNoTracking()
                           .FirstOrDefault(e => e.TeamID == teamId);

            if (teamStat == null)
            {
                var teamStatToAdd = new TeamStats
                {
                    TeamID = teamId
                };

                var createdTeamStat = _ctx.TeamStats.Add(teamStatToAdd);
                _ctx.SaveChanges();
                _ctx.Entry(teamStatToAdd).State = EntityState.Detached;

                teamStat = _ctx.TeamStats.AsNoTracking()
                           .FirstOrDefault(e => e.TeamID == teamId);
            }

            return(_mapper.Map <TeamStat>(teamStat));
        }
Example #16
0
        public Head2HeadWorldCup GetOrCreateByTeams(int team1Id, int team2Id)
        {
            var h2h = _ctx.H2HWorldCup.AsNoTracking()
                      .FirstOrDefault(e => e.Team1ID == team1Id && e.Team2ID == team2Id);

            if (h2h == null)
            {
                var h2hToAdd = new H2HWorldCup
                {
                    Team1ID = team1Id,
                    Team2ID = team2Id
                };

                var createdH2H = _ctx.H2HWorldCup.Add(h2hToAdd);
                _ctx.SaveChanges();
                _ctx.Entry(h2hToAdd).State = EntityState.Detached;

                h2h = _ctx.H2HWorldCup.AsNoTracking()
                      .FirstOrDefault(e => e.Team1ID == team1Id && e.Team2ID == team2Id);
            }

            return(_mapper.Map <Head2HeadWorldCup>(h2h));
        }
        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);
        }
Example #18
0
        private void match(String facultyName, List <Preference> preferences, Student student)
        {
            //add student as rejected in the db at first
            FacultyRankList rejected = new FacultyRankList()
            {
                EGN           = student.EGN,
                ProgrammeName = CONST_REJECTED + ' ' + facultyName,
                TotalGrade    = 0
            };

            context.FacultyRankLists.Add(rejected);
            context.SaveChanges();
            try
            {
                foreach (Preference preference in preferences)
                {
                    int quota = queryManager.getQuota(preference.ProgrammeName, (bool)student.Gender);
                    List <FacultyRankList> rankList = queryManager.getRankListData(preference.ProgrammeName, (bool)student.Gender);
                    double minimalGrade             = 0;
                    double studentCount             = rankList.Count;

                    if (rankList.Count != 0)
                    {
                        minimalGrade = rankList.Min(list => list.TotalGrade);
                    }


                    if (preference.TotalGrade > minimalGrade &&
                        studentCount >= quota &&
                        ((quota >= 2 &&
                          rankList[quota - 2].TotalGrade > minimalGrade) ||
                         (quota == 1 &&
                          rankList[quota - 1].TotalGrade > minimalGrade)
                        ))
                    {
                        var entries = rankList.Where(entry => entry.TotalGrade == minimalGrade);

                        foreach (FacultyRankList entry in entries)
                        {
                            context.FacultyRankLists.Attach(entry);
                            context.FacultyRankLists.Remove(entry);
                        }
                        context.SaveChanges();
                    }

                    if ((preference.TotalGrade > 0 &&
                         preference.TotalGrade >= minimalGrade) ||
                        (preference.TotalGrade < minimalGrade &&
                         studentCount < quota))
                    {
                        FacultyRankList entry = new FacultyRankList()
                        {
                            EGN           = preference.EGN,
                            ProgrammeName = preference.ProgrammeName,
                            TotalGrade    = preference.TotalGrade
                        };

                        context.FacultyRankLists.Add(entry);
                        context.FacultyRankLists.Attach(rejected);
                        context.FacultyRankLists.Remove(rejected);
                        context.SaveChanges();

                        break;
                    }
                }
            }
            catch (Exception e)
            {
                context.FacultyRankLists.Attach(rejected);
                context.FacultyRankLists.Remove(rejected);
                context.SaveChanges();
                throw e;
            }
        }
        public ActionResult Create(Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();

                string newPassword = Membership.GeneratePassword(10, 0);
                Random rnd         = new Random();
                newPassword      = Regex.Replace(newPassword, @"[^a-zA-Z0-9]", m => rnd.Next(0, 10).ToString());
                ViewBag.Password = newPassword;

                String pass = ViewBag.Password;
                WebSecurity.CreateUserAndAccount(student.EGN, ViewBag.Password);
                //WebSecurity.Login(student.EGN, ViewBag.Password);

                //var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
                //var message = new MailMessage();
                //message.To.Add(new MailAddress("*****@*****.**")); //replace with valid value
                //message.From = new MailAddress("*****@*****.**");
                //message.Subject = "Your email subject";
                //message.Body = string.Format(body, "admin",
                //                                   "*****@*****.**", newPassword);
                //message.IsBodyHtml = true;
                //var smtp = new SmtpClient();

                //var credential = new NetworkCredential
                //{
                //    UserName = "******",  // replace with valid value
                //    Password = "******"  // replace with valid value
                //};
                //smtp.Credentials = credential;
                //smtp.Host = "smtp.abv.bg";
                //smtp.Port = 587;
                //smtp.EnableSsl = true;

                ////smtp.SendMailAsync(message);
                //smtp.Send(message);
//this
                //var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
                //MailMessage mail = new MailMessage();
                //mail.To.Add(new MailAddress("*****@*****.**"));
                //mail.From = new MailAddress("*****@*****.**");
                //mail.Subject = "Your email subject";
                //mail.Body = string.Format(body, "admin",
                //                                   "*****@*****.**", newPassword); ;
                //mail.IsBodyHtml = true;
                //SmtpClient smtp = new SmtpClient("smtp.abv.bg", 587);
                //smtp.EnableSsl = true;
                //smtp.UseDefaultCredentials = false;
                //smtp.Credentials =
                //     new System.Net.NetworkCredential("*****@*****.**", "123456789");
                //smtp.Send(mail);



                //using (var smtp = new SmtpClient())
                //{
                //    await smtp.SendMailAsync(message);
                //    //return RedirectToAction("Sent");
                //}

                MembershipUser user = Membership.GetUser(student.EGN);
                //user.GetPassword();

                var roles = (SimpleRoleProvider)Roles.Provider;

                if (!roles.RoleExists("admin"))
                {
                    roles.CreateRole("admin");
                }

                if (!roles.RoleExists("student"))
                {
                    roles.CreateRole("student");
                }

                roles.AddUsersToRoles(new string[] { student.EGN }, new string[] { "student" });
            }

            return(RedirectToAction("Create", "StudentBrowse"));
            //return View(student);
        }