Example #1
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 Edit(Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(student);
 }
Example #3
0
        private void serve(String facultyName, Student student)
        {
            //handle preferences
            List<Preference> preferences = queryManager.getStudentPreferencesByFaculty(student.EGN, facultyName);

            //handle grading
            Grader grader = new Grader(context);
            grader.grade(student.EGN, preferences);

            //handle ranking
            match(facultyName, preferences, student);
        }
        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("[email protected]")); //replace with valid value
                //message.From = new MailAddress("[email protected]");
                //message.Subject = "Your email subject";
                //message.Body = string.Format(body, "admin",
                //                                   "[email protected]", newPassword);
                //message.IsBodyHtml = true;
                //var smtp = new SmtpClient();

                //var credential = new NetworkCredential
                //{
                //    UserName = "[email protected]",  // replace with valid value
                //    Password = "123456789"  // 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("[email protected]"));
                //mail.From = new MailAddress("[email protected]");
                //mail.Subject = "Your email subject";
                //mail.Body = string.Format(body, "admin",
                //                                   "[email protected]", newPassword); ;
                //mail.IsBodyHtml = true;
                //SmtpClient smtp = new SmtpClient("smtp.abv.bg", 587);
                //smtp.EnableSsl = true;
                //smtp.UseDefaultCredentials = false;
                //smtp.Credentials =
                //     new System.Net.NetworkCredential("[email protected]", "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);
        }