Example #1
0
 public static void RegisterLoginAttemp(string pesel, bool succesful, bool valid)
 {
     using (var db = new ElectionsEntities())
     {
         Loginattemp loginattemp = new Loginattemp()
         {
             date      = DateTime.Now,
             pesel     = pesel,
             valid     = (valid == true ? (byte)1 : (byte)0),
             succesful = (succesful == true ? (byte)1 : (byte)0),
         };
         db.Loginattemps.Add(loginattemp);
         db.SaveChanges();
     }
 }
Example #2
0
 public static void RegisterAttempToVoteWitoutRights()
 {
     using (var db = new ElectionsEntities())
     {
         Vote vote = new Vote()
         {
             date        = DateTime.Now,
             idcandidate = null,
             valid       = 0,
             withRights  = 0,
         };
         db.Votes.Add(vote);
         db.SaveChanges();
     }
 }
 public static void UpdateElector(Electorate electorate)
 {
     using (var db = new ElectionsEntities())
     {
         var result = db.Electorates.SingleOrDefault(b => b.idelectorate == electorate.idelectorate);
         if (result != null)
         {
             result.name    = electorate.name;
             result.surname = electorate.surname;
             result.pesel   = electorate.pesel;
             result.voted   = electorate.voted;
             result.logged  = electorate.logged;
             db.SaveChanges();
         }
     }
 }
 public static Electorate AddNewElectorate(Electorate electorateTemplate)
 {
     using (var db = new ElectionsEntities())
     {
         Electorate check = new Electorate();
         check.pesel = electorateTemplate.pesel;
         if (GetElectorate(check) != null)
         {
             //there already is electorate with provided pesel
             return(null);
         }
         db.Electorates.Add(electorateTemplate);
         db.SaveChanges();
         return(electorateTemplate);
     }
 }
        public static void Vote(ref Electorate electorate, Candidate candidate)
        {
            using (var db = new ElectionsEntities())
            {
                Vote vote = new Vote()
                {
                    date        = DateTime.Now,
                    idcandidate = candidate?.idcandidates,
                    valid       = candidate != null ? (byte)1 : (byte)0,
                    withRights  = 1,
                };
                db.Votes.Add(vote);

                electorate.voted = 1;
                ElectorateFacade.UpdateElector(electorate);

                db.SaveChanges();
            }
        }