public bool WorksHere(VotingVenue v) { return Validated && _workplaces.Contains(v); }
private void TestWorksHere(VotingVenue votingVenue) { if (!this.PermittedToWorkHere(votingVenue)) throw new PermissionException(_user, "You don't work at this voting venue"); }
private HashSet<VotingVenue> PriGetWorkplaces(User user) { Contract.Requires(this.Transacting(), "This method must be performed in a transaction."); Contract.Requires(user != null, "The input user must not be null!"); Contract.Ensures(Contract.Result<HashSet<VotingVenue>>() != null); var output = new HashSet<VotingVenue>(); if (user.DbId < 1) return output; //The user CAN not exist in the database... MySqlCommand cmd = Prepare("SELECT " + " v.id, " + " v.address, " + " v.name " + "FROM " + " user u " + " INNER JOIN " + " workplace w " + " ON " + " u.id = w.user_id " + " INNER JOIN " + " voting_venue v " + " ON " + " v.id = w.voting_venue_id " + "WHERE " + " u.id=@id"); cmd.Parameters.AddWithValue("@id", user.DbId); Query(cmd, rdr => { while (rdr.Read()) { VotingVenue venue = new VotingVenue( rdr.GetInt32("id"), rdr.GetString("name"), rdr.GetString("address")); output.Add(venue); } }); return output; }
/// <summary> /// Is my user permitted to work on this voting venue? /// </summary> /// <param name="v"></param> /// <param name="msg"></param> /// <returns></returns> public bool PermittedToWorkHere(VotingVenue v, string msg = "You can't perform this action, as you don't work in the right voting venue, or have global access") { return _user.WorksHere(v) || this.ActionPermitted(SystemAction.AllVotingPlaces); }