Example #1
0
        public ActionResult DeleteApplicant(Applicant applicant)
        {
            // Confirm that an applicant with the same ID exists in the database
            var queriedApplicant = db.Applicants.Find(applicant.ID);

            if (queriedApplicant == null)
            {
                return(HttpNotFound());
            }

            // Remove from lists (and run lottery to place waitlisted applicant if the student was selected)
            if (WasLotteryRun())
            {
                var waitlisteds = db.Waitlisteds.Where(w => w.ApplicantID == applicant.ID).ToList();
                db.Waitlisteds.RemoveRange(waitlisteds);

                var selected = db.Selecteds.FirstOrDefault(s => s.ApplicantID == applicant.ID);
                if (selected != null)
                {
                    var school = selected.School;

                    // Remove the selected applicant
                    db.Selecteds.Remove(selected);

                    // Get the waitlist to pass into the lottery algorithm
                    var waitlistedApplicants = Utils.GetApplicants(db.Waitlisteds.Where(w => w.SchoolID == school.ID).OrderBy(w => w.Rank).ToList());

                    // Run the lottery to fill the slot
                    var lottery = new SchoolLottery(db);
                    lottery.Run(school, waitlistedApplicants, false);

                    // Remove the newly selected applicants from the selected school from other waitlists
                    // (does it for all selecteds in the school since we don't know which student was the one filled in at this point)
                    var newSelecteds      = school.Selecteds;
                    var removeWaitlisteds = new List <Waitlisted>();
                    foreach (var newSelected in newSelecteds)
                    {
                        var otherApplicantWaitlisteds =
                            db.Waitlisteds.Where(w => w.ApplicantID == newSelected.ApplicantID).ToList();
                        removeWaitlisteds.AddRange(otherApplicantWaitlisteds);
                    }
                    db.Waitlisteds.RemoveRange(removeWaitlisteds);
                }
            }


            // Remove the applicant entirely from the system
            db.Applicants.Remove(queriedApplicant);
            db.SaveChanges();

            return(RedirectToAction("ViewApplicants"));
        }
Example #2
0
        public ActionResult RunLottery()
        {
            if (!WasLotteryRun())
            {
                // Run the selection algorithm for each school
                var schoolLottery = new SchoolLottery(db);
                foreach (var school in db.Schools.ToList())
                {
                    schoolLottery.Run(school);
                }

                // Make sure applicants were not selected for more than one school (or waitlisted on any others if they were selected)
                var reconciler = new CrossSchoolReconciler(db);
                reconciler.Reconcile();

                // Save a record that the lottery was run
                var globalConfig = db.GlobalConfigs.First();
                globalConfig.LotteryRunDate = DateTime.Now;
                db.GlobalConfigs.AddOrUpdate(globalConfig);
                db.SaveChanges();
            }

            return(RedirectToAction("ViewApplicants"));
        }