public VoteEventArgs Vote(string question) { VoteEventArgs voteEventArgs = new VoteEventArgs(); voteEventArgs.Question = question; OnVote?.Invoke(this, voteEventArgs); return(voteEventArgs); }
private void voteManager_VoteAdded(object sender, VoteEventArgs args) { if (Requester.IsLogged && !Portal.Request.IsRequesterAttached(args.RequestID.Value, Requester.LoggedUserID.Value)) { var dto = new RequestRequesterDTO(); dto.RequestID = args.RequestID.Value; dto.RequesterID = Requester.Logged.ID; Portal.Request.AddRequester(args.RequestID.Value, dto); } }
/// <summary> /// Add a new vote /// </summary> /// <param name="vote"></param> /// <returns></returns> public Vote Add(Vote vote) { var e = new VoteEventArgs {Vote = vote}; EventManager.Instance.FireBeforeVoteMade(this, e); if (!e.Cancel) { _context.Vote.Add(vote); EventManager.Instance.FireAfterVoteMade(this, new VoteEventArgs {Vote = vote}); } return vote; }
public bool Submit() { bool retval = false; VoteEventArgs e = new VoteEventArgs(); FireBeforeSubmitVote(e); if (!e.Cancel) { retval = true; FireAfterSubmitVote(e); } return(retval); }
public void VoterHandler(object sender, VoteEventArgs e) { switch (new Random().Next(0, 3)) { case 0: e.VoteFor += 1; break; case 1: e.VoteAgaints += 1; break; case 2: e.VoteAbstained += 1; break; } }
static void Main(string[] args) { ElectoralComission electoralComission = new ElectoralComission(); Voiter[] voiters = new Voiter[10]; for (int i = 0; i < 10; i++) { voiters[i] = new Voiter(); electoralComission.OnVote += voiters[i].VoterHandler; } VoteEventArgs voteEventArgs = electoralComission.Vote("Привет?"); Console.WriteLine($"Вопрос был: {voteEventArgs.Question}"); Console.WriteLine($"\tЗа проголосовали:\t\t {voteEventArgs.VoteFor}"); Console.WriteLine($"\tПротив проголосовали:\t\t {voteEventArgs.VoteAgaints}"); Console.WriteLine($"\tВоздержались от голосования:\t {voteEventArgs.VoteAbstained}"); Console.ReadKey(); }
/// <summary> /// Add a new vote /// </summary> /// <param name="vote"></param> /// <returns></returns> public Vote Add(Vote vote) { var e = new VoteEventArgs { Vote = vote }; EventManager.Instance.FireBeforeVoteMade(this, e); if (!e.Cancel) { _context.Vote.Add(vote); EventManager.Instance.FireAfterVoteMade(this, new VoteEventArgs { Vote = vote }); } return(vote); }
/// <summary> /// Add a new vote /// </summary> /// <param name="vote"></param> /// <returns></returns> public Vote Add(Vote vote) { var e = new VoteEventArgs { Vote = vote, Api = _api }; EventManager.Instance.FireBeforeVoteMade(this, e); if (!e.Cancel) { _voteRepository.Add(vote); EventManager.Instance.FireAfterVoteMade(this, new VoteEventArgs { Vote = vote, Api = _api }); } return(vote); }
public bool Submit() { bool retval = false; VoteEventArgs e = new VoteEventArgs(); FireBeforeSubmitVote(e); if (!e.Cancel) { retval = true; FireAfterSubmitVote(e); } return retval; }
protected virtual void FireBeforeSubmitVote(VoteEventArgs e) { _e.FireCancelableEvent(BeforeSubmitVote, this, e); }
protected virtual void FireAfterSubmitVote(VoteEventArgs e) { _e.FireCancelableEvent(AfterSubmitVote, this, e); }
private void EventManagerInstanceAfterVoteMade(object sender, VoteEventArgs args) { _eventTestStr = TestString; }
private void EventManagerInstanceBeforeVoteMadeCancel(object sender, VoteEventArgs args) { args.Cancel = true; }
private void EventManagerInstanceBeforeVoteMadeAllow(object sender, VoteEventArgs args) { args.Cancel = false; }