public async Task <bool> IncrementVotesNumAsync(bool isVoteGood) { try { using (var context = new ElectoralDatabase()) { var vote = context.Votes.Single(); if (isVoteGood) { vote.Valid_Votes++; } else { vote.Bad_Votes++; } context.Entry(vote).State = System.Data.Entity.EntityState.Modified; await context.SaveChangesAsync(); return(true); } } catch { return(false); } }
public async Task <bool> CreatePersonAsync(Person person) { try { using (var context = new ElectoralDatabase()) { context.Persons.Add(person); context.Entry(person).State = System.Data.Entity.EntityState.Added; await context.SaveChangesAsync(); return(true); } } catch { return(false); } }
public async Task <bool> IncrementPersonWithLawTriedToVote() { try { using (var context = new ElectoralDatabase()) { var vote = context.Votes.Single(); vote.WithoutLaw_TriesNum++; context.Entry(vote).State = System.Data.Entity.EntityState.Modified; await context.SaveChangesAsync(); return(true); } } catch { return(false); } }
public async Task <bool> UpdateSessionAsync(string pesel, string key, int timestamp) { try { using (var context = new ElectoralDatabase()) { var service = context.LoginServices.FirstOrDefault(p => p.pesel == pesel); if (service == null) { var loginService = new LoginService() { guid = key, timestamp = timestamp, pesel = pesel }; context.LoginServices.Add(loginService); context.Entry(loginService).State = System.Data.Entity.EntityState.Added; } else { service.timestamp = timestamp; service.guid = key; context.Entry(service).State = System.Data.Entity.EntityState.Modified; } await context.SaveChangesAsync(); return(true); } } catch { return(false); } }