예제 #1
0
        public ActionResult Delete(Voter theVoter)
        {
            try
            {

                Voter theRealVoter = work.VoterRepository.GetByID(theVoter.VoterID);
                // Membership.GetUser
                // Membership.DeleteUser(theRealVoter.IdentityNumber, true);

                try
                {
                    ((SimpleMembershipProvider)Membership.Provider).DeleteAccount(theRealVoter.IdentityNumber);

                    ((SimpleMembershipProvider)Membership.Provider).DeleteUser(theRealVoter.IdentityNumber, true);
                }
                catch (Exception e)
                {
                    work.VoterRepository.Delete(theRealVoter);

                    work.Save();
                }

                work.VoterRepository.Delete(theRealVoter);
                //
                work.Save();
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
예제 #2
0
        public ActionResult Create(Voter model)
        {
            model.VotedTime = DateTime.Now;
            model.LoggedInAttemptsAfterVoting = 0;
            // model.Voted = false;
            //  model.
            model.Voted = false;
            try
            {
                if (!(ModelState.IsValid))
                {
                    View(model);
                }
                work.VoterRepository.Insert(model);
                Membership.CreateUser(model.IdentityNumber, model.Password);
                work.Save();

                //  WebSecurity.CreateUserAndAccount(model.IdentityNumber, model.Password);
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View(model);
            }
        }
예제 #3
0
 public static async Task AddVoter(Voter voter)
 {
     using var db = new NamikoDbContext();
     db.Voters.Add(voter);
     await db.SaveChangesAsync();
 }
예제 #4
0
        public ActionResult Populate(IEnumerable<HttpPostedFileBase> file)
        {
            HttpPostedFileBase theFile = Request.Files[0];
            var fileName = Path.GetFileName(Request.Files[0].FileName);

            IExcelDataReader excelReader = null;
            //if ((fileExtension.EndsWith(".xlsx")))
            //{
            //    //2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
            //    excelReader = ExcelReaderFactory.CreateOpenXmlReader(theFile.InputStream);
            //}

            //if ((fileExtension.EndsWith(".xls")))
            //{

            //1. Reading from a binary Excel file ('97-2003 format; *.xls)
            excelReader = ExcelReaderFactory.CreateBinaryReader(theFile.InputStream);
            //  }
            // ExcelDataReader reader = new ExcelDataReader(ExcelFileUpload.PostedFile.InputStream);

            /// FileStream stream = File.Open(Request.Files[0], FileMode.Open, FileAccess.Read);

            //...

            //...
            //3. DataSet - The result of each spreadsheet will be created in the result.Tables
            DataSet result = excelReader.AsDataSet();
            //  ...
            //4. DataSet - Create column names from first row
            excelReader.IsFirstRowAsColumnNames = true;
            DataSet result2 = excelReader.AsDataSet();

            //5. Data Reader methods
            int counter = 0;

            int usernameCouner = 7000;
            var chars = "xckheayrydzjcmgncb4au9w8xu5ur93hmb3mqa4j3n3nwm3ktvj6c2vj9kckdnv3n4bsv6a8ev9xjcvk3n5m7rka9a5xz7hz8zrmn3kz3n4nzmavn3kwn7k8kvc3n2a9s3muabtfbusk347sbua3hdkcks28jk";
            while (excelReader.Read())
            {
                if (counter != 0)
                {
                    var random = new Random();
                    string randomPassword = new string(Enumerable.Repeat(chars, 6).Select(s => s[random.Next(s.Length)]).ToArray());

                    Voter theVoter = new Voter();
                    //theVoter.IdentityNumber = theMatric;
                    try
                    {
                        theVoter.Department = excelReader.GetString(1).TrimEnd().TrimStart(); ;// theBrokenData[0].TrimEnd().TrimStart();

                        usernameCouner = usernameCouner + 1;
                        theVoter.FirstName = excelReader.GetString(3).TrimEnd().TrimStart();
                        theVoter.Matric = excelReader.GetString(4).TrimEnd().TrimStart();
                        theVoter.IdentityNumber = Convert.ToString(usernameCouner);//usernameCouner + 1; //excelReader.GetValue(5).ToString().TrimEnd().TrimStart();

                        theVoter.Password = randomPassword;
                        theVoter.VotedTime = DateTime.Now;

                        // theVoter.LastName = theBrokenData[5].TrimEnd().TrimStart(); ;
                        theVoter.Voted = false;

                        List<Voter> theVoters = work.VoterRepository.Get(a => a.IdentityNumber == theVoter.IdentityNumber).ToList();
                        if (theVoter.IdentityNumber != null && theVoters.Count() > 0)
                        {
                            string k = "f";
                        }
                        //  theID = WebSecurity.GetUserId(theVoter.IdentityNumber);
                        if (theVoters.Count == 0 && theVoter.FirstName != null && theVoter.IdentityNumber != null && theVoter.Department != null)
                        {
                            work.VoterRepository.Insert(theVoter);

                            Membership.CreateUser(theVoter.IdentityNumber, randomPassword);
                            work.Save();
                            //  WebSecurity.CreateUserAndAccount(theVoter.IdentityNumber, randomPassword);
                        }
                    }
                    catch (Exception e)
                    {
                        continue;
                    }
                }
                counter = counter + 1;
            }

            //// int theID = 0;

            //var random = new Random();
            //// string result = new string(Enumerable.Repeat(chars,6).Select(s=>s[random.Next(s.Length)]).ToArray());

            //FileStream fs = new FileStream("C:\\Users\\kazeem\\Desktop\\School Projects\\doctorsreal.txt", FileMode.Open, FileAccess.Read);
            //StreamReader sr = new StreamReader(fs);
            //// Math.
            ////  string theLast = null;
            //// string theMatric = null;
            //while (!(sr.EndOfStream))
            //{
            //    string randomPassword = new string(Enumerable.Repeat(chars, 6).Select(s => s[random.Next(s.Length)]).ToArray());
            //    string theMatric = sr.ReadLine().Trim();
            //    string[] theBrokenData = theMatric.Split('\t');

            //    // theBrokenData[6];

            //    Voter theVoter = new Voter();
            //    //theVoter.IdentityNumber = theMatric;
            //    theVoter.IdentityNumber = theBrokenData[3].TrimEnd().TrimStart();
            //    theVoter.Department = theBrokenData[0].TrimEnd().TrimStart();
            //    theVoter.Password = randomPassword;
            //    theVoter.VotedTime = DateTime.Now;
            //    theVoter.FirstName = theBrokenData[2].TrimEnd().TrimStart(); ;
            //    // theVoter.LastName = theBrokenData[5].TrimEnd().TrimStart(); ;
            //    theVoter.Voted = false;

            //    List<Voter> theVoters = work.VoterRepository.Get(a => a.IdentityNumber == theVoter.IdentityNumber).ToList();
            //    //  theID = WebSecurity.GetUserId(theVoter.IdentityNumber);
            //    if (theVoters.Count == 0)
            //    {
            //        work.VoterRepository.Insert(theVoter);

            //        Membership.CreateUser(theVoter.IdentityNumber, randomPassword);
            //        work.Save();
            //        //  WebSecurity.CreateUserAndAccount(theVoter.IdentityNumber, randomPassword);
            //    }
            //    //  theLast  =theMatric;
            //}
            //sr.Close();
            //fs.Close();
            //  theLast = theMatric;
            // List<Post> theposts = work.PostRepository.Get().ToList();
            // return View("Result", theposts);
            return View();
        }
예제 #5
0
        public ActionResult Edit(Voter theVoter, string newPassword)
        {
            try
            {
                if (TryUpdateModel(theVoter))
                {
                    if (string.IsNullOrEmpty(newPassword))
                    {
                        work.VoterRepository.Update(theVoter);
                        work.Save();
                    }
                    else
                    {
                        if (newPassword.Length < 6)
                        {
                            ModelState.AddModelError("", "Passwrod Must have a minimum of 6 Characters");

                            return View();
                        }
                        else
                        {
                            WebSecurity.ChangePassword(theVoter.IdentityNumber, theVoter.Password, newPassword);
                            theVoter.Password = newPassword;
                            work.VoterRepository.Update(theVoter);
                            work.Save();
                            return RedirectToAction("Index");
                        }
                    }

                }
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }