// GET: /Voters/Create
 public ActionResult Create(int id)
 {
     Voter voter = new Voter();
     Symposium symposium = db.Symposiums.Find(id);
     voter.Symposium = symposium;
     voter.symposiumID = id;
     return View(voter);
 }
示例#2
0
 public static Vote Cast(Project project, Voter voter, int amount)
 {
     Vote vote = new Vote();
     vote.amount = amount;
     vote.voterID = voter.ID;
     vote.projectID = project.ID;
     vote.created_at = DateTime.Now.ToString("HH:mm");
     return vote;
 }
        public ActionResult generate_voters(FormCollection form)
        {
            Symposium symposium = db.Symposiums.Find(Convert.ToInt32(form["symposium_id"]));
            string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            string year = symposium.year;
            year = year.Substring(2, year.Length - 2);
            string semester = symposium.semester;
            if (semester == "Spring" || semester == "spring")
            {
                semester = semester.Remove(semester.Length - 5);
            }
            else
            {
                semester = semester.Remove(semester.Length - 3);
            }

            for (int i = 1; i <= Convert.ToInt32(form["voter_amount"]); i++)
            {

                Voter voter = new Voter();
                string result = new string(Enumerable.Repeat(chars, 3).Select(s => s[random.Next(s.Length)]).ToArray());
                result = result + semester + year;
                result = Char.ToLowerInvariant(result[0]) + result.Substring(1);
                voter.voting_id = result;
                voter.symposiumID = symposium.ID;
                db.Voters.Add(voter);

            }
            db.SaveChanges();
            return RedirectToAction("Details", "Symposiums", new { id = Convert.ToInt32(form["symposium_id"])});
        }