public async Task <TransactionCreatedReply> SetPhasingOnlyControl(VotingModel controlVotingModel, long controlQuorum, CreateTransactionParameters parameters, long?controlMinBalance = null, VotingModel?controlMinBalanceModel = null, ulong?controlHolding = null, IEnumerable <string> controlWhitelisted = null, Amount controlMaxFees = null, int?controlMinDuration = null, int?controlMaxDuration = null) { var queryParameters = new Dictionary <string, List <string> > { { Parameters.ControlVotingModel, new List <string> { ((int)controlVotingModel).ToString() } }, { Parameters.ControlQuorum, new List <string> { controlQuorum.ToString() } } }; parameters.AppendToQueryParameters(queryParameters); queryParameters.AddIfHasValue(Parameters.ControlMinBalance, controlMinBalance); queryParameters.AddIfHasValue(Parameters.ControlMinBalanceModel, controlMinBalanceModel != null ? (int)controlMinBalanceModel : (int?)null); if (controlWhitelisted != null) { queryParameters.Add(Parameters.ControlWhitelisted, controlWhitelisted.ToList()); } queryParameters.AddIfHasValue(Parameters.ControlMaxFees, controlMaxFees?.Nqt.ToString()); queryParameters.AddIfHasValue(Parameters.ControlMinDuration, controlMinDuration); queryParameters.AddIfHasValue(Parameters.ControlMaxDuration, controlMaxDuration); return(await Post <TransactionCreatedReply>("setPhasingOnlyControl", queryParameters)); }
public IActionResult Vote(Guid sessionId, [FromBody] VotingModel votingModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (sessionId == Guid.Empty || votingModel == null) { return(BadRequest()); } try { var voting = new Voting { Date = DateTime.Now, SessionId = sessionId, Id = Guid.NewGuid(), Value = votingModel.Change }; Service.AddVoting(sessionId, voting); return(Ok(new { Success = true })); } catch (Exception) { return(BadRequest()); } }
public IActionResult VoteAll(VotingModel voting) { voting.VotingTime = DateTime.Now; var member = HttpContext.Session.GetObjectFromJson <MemberModel>("Member"); if (member == null) { return(RedirectToAction("Login", "Login")); } else { try { using (TWHContext dbContext = new TWHContext()) { dbContext.InternalRegimeVoteAll(voting); } } catch (Exception ex) { AddException(ex, "VoteAll"); } return(Ok()); } }
public async Task <TransactionCreatedReply> CreatePoll(string name, string description, int finishHeight, VotingModel votingModel, int minNumberOfOptions, int maxNumberOfOptions, int minRangeValue, int maxRangeValue, List <string> options, CreateTransactionParameters parameters, long?minBalance = null, MinBalanceModel?minBalanceModel = null, ulong?holdingId = null) { var queryParameters = new Dictionary <string, string> { { Parameters.Name, name }, { Parameters.Description, description }, { Parameters.FinishHeight, finishHeight.ToString() }, { Parameters.VotingModel, ((int)votingModel).ToString() }, { Parameters.MinNumberOfOptions, minNumberOfOptions.ToString() }, { Parameters.MaxNumberOfOptions, maxNumberOfOptions.ToString() }, { Parameters.MinRangeValue, minRangeValue.ToString() }, { Parameters.MaxRangeValue, maxRangeValue.ToString() } }; for (var i = 0; i < options.Count; i++) { queryParameters.Add(Parameters.Option + i.ToString().PadLeft(2, '0'), options[i]); } queryParameters.AddIfHasValue(Parameters.MinBalance, minBalance); queryParameters.AddIfHasValue(Parameters.MinBalanceModel, minBalanceModel); queryParameters.AddIfHasValue(Parameters.Holding, holdingId); parameters.AppendToQueryParameters(queryParameters); return(await Post <TransactionCreatedReply>("createPoll", queryParameters)); }
private void CreatePoll(VotingModel votingModel, MinBalanceModel balanceModel, ulong?holdingId) { var name = Utilities.GenerateRandomString(10); var description = Utilities.GenerateRandomString(30); var finishHeight = TestSettings.MaxHeight + 1000; const int minNumberOfOptions = 1; const int maxNumberOfOptions = 1; const int minRangeValue = 0; const int maxRangeValue = 1; var options = new List <string> { "How are you doing?" }; const int minBalance = 1; var createPollParameters = new CreatePollParameters(name, description, finishHeight, votingModel, minNumberOfOptions, maxNumberOfOptions, minRangeValue, maxRangeValue, options) { MinBalance = minBalance, MinBalanceModel = balanceModel, HoldingId = holdingId }; var createPollReply = _votingSystemService.CreatePoll(createPollParameters, CreateTransaction.CreateTransactionBySecretPhrase(fee: Amount.CreateAmountFromNxt(10))).Result; VerifyCreatePollParameters(createPollParameters, createPollReply.Transaction.Attachment as MessagingPollCreationAttachment); }
public void ShowVoting(ActivityViewState viewState, VotingModel model) { this.Model = model; PageNavigator.Title = viewState.Title; HeaderViewModel.ViewState.Push(viewState); PullToRefresh.IsRefreshing = true; sender.ReceiveComments(this); }
public CreateTransactionPhasing(int finishHeight, VotingModel votingModel, long quorum) { Phased = true; FinishHeight = finishHeight; VotingModel = votingModel; Quorum = quorum; WhiteListed = new List <Account>(); LinkedFullHash = new List <BinaryHexString>(); }
public ActionResult Vote(VotingModel voting) { var nextSprint = SprintHelper.GetNextSprint(); var user = User.Identity.GetUserName(); Repository.SaveVotes(user, nextSprint, voting); return(RedirectToAction("Index")); }
public async void OnVotingSelected(ActivityViewState viewState, VotingModel model) { try { var vm = await commutator.GoToPage <VotingDetailPresenter>(PageNavigator.Navigation); vm.ShowVoting(viewState, model); } catch (Exception ex) { logger.Error(ex); } }
void IVotingAdditing.Add(VotingModel v) { long id = 1 + HousingCoo.Data.Services.Storage.Instance.Votings.Keys.Max(); v.Id = id; VotingEntity entity = v.Map <VotingEntity>(); HousingCoo.Data.Services.Storage.Instance.Votings.Add(id, entity); HousingCoo.Data.Services.Storage.Instance.Comments.Add(id, new List <CommentVotingEntity>()); }
private void CreatePollByNqt() { using (Logger = new TestsessionLogger(_logger)) { const VotingModel votingModel = VotingModel.Nqt; const MinBalanceModel balanceModel = MinBalanceModel.Nqt; CreatePoll(votingModel, balanceModel, null); } }
private void CreatePollByAsset() { using (Logger = new TestsessionLogger(_logger)) { const VotingModel votingModel = VotingModel.Asset; const MinBalanceModel balanceModel = MinBalanceModel.Asset; var assetId = TestSettings.ExistingAssetId; CreatePoll(votingModel, balanceModel, assetId); } }
private void CreatePollByCurrency() { using (Logger = new TestsessionLogger(_logger)) { const VotingModel votingModel = VotingModel.Account; const MinBalanceModel balanceModel = MinBalanceModel.Currency; var currencyId = TestSettings.ExistingCurrencyId; CreatePoll(votingModel, balanceModel, currencyId); } }
public static VotingStrategy CreateStrategy(VotingType votingType, VotingModel model) { switch (votingType) { case VotingType.Open: return new OpenVotingStrategy(model.Contest, model.Photo, model.UserId); case VotingType.Closed: return new ClosedVotingStrategy(model.Contest, model.Photo, model.UserId); default: throw new ArgumentException(); } }
public CreatePollParameters(string name, string description, int finishHeight, VotingModel votingModel, int minNumberOfOptions, int maxNumberOfOptions, int minRangeValue, int maxRangeValue, List <string> options) { Name = name; Description = description; FinishHeight = finishHeight; VotingModel = votingModel; MinNumberOfOptions = minNumberOfOptions; MaxNumberOfOptions = maxNumberOfOptions; MinRangeValue = minRangeValue; MaxRangeValue = maxRangeValue; Options = options; }
public static void SaveVotes(string voter, int sprint, VotingModel voting) { using (var ctx = new AgileContext()) { var oldVotes = ctx.Votes.Where(v => v.Sprint == sprint && v.Voter == voter); ctx.Votes.RemoveRange(oldVotes); foreach (var v in voting.Votes.Where(vo => vo.IsVoted)) { ctx.Votes.Add(new VoteModel(sprint, DateTime.Now, voter, ctx.Restaurants.Single(r => r.Id == v.RestaurantId))); } ctx.SaveChanges(); } }
public async System.Threading.Tasks.Task <ActionResult> VoitingMain() { if (User.IsInRole("admin")) { return(RedirectToAction("Home", "Admin")); } var student = await UserManager.FindByNameAsync(User.Identity.Name); var data = new VotingModel(); var info = data.InfoForRaitingList(student.GroupId, student.Id); return(View(info)); }
internal MessagingPollCreationAttachment(JToken attachments) { Description = GetAttachmentValue <string>(attachments, Parameters.Description); FinishHeight = GetAttachmentValue <int>(attachments, Parameters.FinishHeight); HoldingId = ulong.Parse(GetAttachmentValue <string>(attachments, Parameters.Holding)); MaxNumberOfOptions = GetAttachmentValue <int>(attachments, Parameters.MaxNumberOfOptions); MaxRangeValue = GetAttachmentValue <int>(attachments, Parameters.MaxRangeValue); MinBalance = GetAttachmentValue <long>(attachments, Parameters.MinBalance); MinBalanceModel = (MinBalanceModel)GetAttachmentValue <int>(attachments, Parameters.MinBalanceModel); MinRangeValue = GetAttachmentValue <int>(attachments, Parameters.MinRangeValue); MinNumberOfOptions = GetAttachmentValue <int>(attachments, Parameters.MinNumberOfOptions); Name = GetAttachmentValue <string>(attachments, Parameters.Name); Options = ParseOptions(attachments.SelectToken(Parameters.Options)).ToList(); VotingModel = (VotingModel)GetAttachmentValue <int>(attachments, Parameters.VotingModel); }
public IActionResult CloseVoting(int?id, ApplicationDbContext context) { var Event = context.EventModel.Find(id); var voting = new VotingModel(); foreach (var elem in context.VotingModel.ToList().Where(a => a.Event == Event)) { voting = elem; } if (voting.IsOpened) { voting.IsOpened = false; Dictionary <VotingModel.Formats, int> results = new Dictionary <VotingModel.Formats, int>(); results.Add(VotingModel.Formats.Standard, voting.Stand); results.Add(VotingModel.Formats.Modern, voting.Mod); results.Add(VotingModel.Formats.Pauper, voting.Pau); results.Add(VotingModel.Formats.Rainbow, voting.Rain); results.Add(VotingModel.Formats.Draft, voting.Draft); results.Add(VotingModel.Formats.Singleton, voting.Sing); results.Add(VotingModel.Formats.Tribal, voting.Tri); results.Add(VotingModel.Formats.Peasant, voting.Pea); results.Add(VotingModel.Formats.Warband, voting.War); results.Add(VotingModel.Formats.Backdraft, voting.Back); Event.Format = results.Keys.First(); foreach (var elem in results) { if (elem.Value > results[Event.Format]) { Event.Format = elem.Key; } } voting.Winner = Event.Format.ToString(); Event.isVotingFinished = true; voting.IsOpened = false; context.VotingModel.Update(voting); context.EventModel.Update(Event); context.SaveChanges(); } return(null); }
public ActionResult Index() { var nextSprint = SprintHelper.GetNextSprint(); ViewBag.Title = $"Teamlunch Sprint {nextSprint}"; var isWheelTime = SprintHelper.IsWheelTime(); if (isWheelTime) { var votesByRestaurant = Repository.GetRestaurants(nextSprint); var votedRestaurants = new List <RestaurantModel>(); foreach (var restaurant in votesByRestaurant) { foreach (var v in restaurant) { votedRestaurants.Add(v.Restaurant); } } votedRestaurants.Shuffle(); votedRestaurants.Shuffle(); votedRestaurants.Shuffle(); var wheelModel = new WheelModel(nextSprint, isWheelTime, votedRestaurants, votesByRestaurant); return(View(wheelModel)); } else { var restaurant = Repository.GetRestaurants(); var votes = Repository.GetVotes(nextSprint); var user = User.Identity.GetUserName(); IList <RestaurantVote> restaurantVotes = restaurant.Select(r => new RestaurantVote { RestaurantId = r.Id, RestaurantName = r.Name, IsVoted = votes[user].Any(v => v.Restaurant.Id == r.Id) }).ToList(); var votingModel = new VotingModel(restaurantVotes); return(View("Vote", votingModel)); } }
public async System.Threading.Tasks.Task <ActionResult> Votings(int?id) { var votingControle = new VotingModel(); var studentData = await UserManager.FindByNameAsync(User.Identity.Name); if (votingControle.CheckVote(int.Parse(id.ToString()), studentData)) { return(RedirectToAction("TimeOut")); } if (id == null) { return(HttpNotFound()); } var info = votingControle.Voiting(int.Parse(id.ToString()), studentData.GroupId, studentData.Id); return(View(info)); }
internal AccountControlSetPhasingOnlyAttachment(JToken attachments) { ControlMaxFees = Amount.CreateAmountFromNqt(GetAttachmentValue <long>(attachments, Parameters.ControlMaxFees)); ControlMinDuration = GetAttachmentValue <int>(attachments, Parameters.ControlMinDuration); ControlMaxDuration = GetAttachmentValue <int>(attachments, Parameters.ControlMaxDuration); var phasing = attachments.SelectToken(Parameters.PhasingControlParams); PhasingHoldingId = GetAttachmentValue <ulong>(phasing, Parameters.PhasingHolding); PhasingQuorum = GetAttachmentValue <long>(phasing, Parameters.PhasingQuorum); PhasingMinBalance = GetAttachmentValue <long>(phasing, Parameters.PhasingMinBalance); PhasingMinBalanceModel = (MinBalanceModel)GetAttachmentValue <int>(phasing, Parameters.PhasingMinBalanceModel); PhasingVotingModel = (VotingModel)GetAttachmentValue <int>(phasing, Parameters.PhasingVotingModel); if (phasing.SelectToken(Parameters.PhasingWhitelist) != null) { var array = (JArray)phasing.SelectToken(Parameters.PhasingWhitelist); PhasingWhitelist = array.ToObject <ulong[]>(); } }
public IActionResult Vote(Guid sessionId, [FromBody] VotingModel votingModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (sessionId == Guid.Empty || votingModel == null) { return(BadRequest()); } try { var voting = new Voting { Date = DateTime.Now, SessionId = sessionId, Id = Guid.NewGuid(), Value = votingModel.Change }; Service.AddVoting(sessionId, voting); _telemetryClient.TrackEvent("VotedForSession", new Dictionary <string, string> { { "sessionId", sessionId.ToString() }, { "change", votingModel.Change.ToString() } }); return(Ok(new { Success = true })); } catch (Exception exception) { _telemetryClient.TrackException(exception); return(StatusCode(500)); } finally { _telemetryClient.Flush(); } }
public async System.Threading.Tasks.Task <ActionResult> Votings(VotingViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var votingControle = new VotingModel(); var studentData = await UserManager.FindByNameAsync(User.Identity.Name); if (votingControle.CheckVote(model.idTeacher, studentData)) { return(RedirectToAction("TimeOut")); } votingControle.FixVoting(int.Parse(model.idTeacher.ToString()), studentData); votingControle.CalculateVotings(model); return(RedirectToAction("VoitingMain", "Raiting")); }
public IActionResult StartLeague(LeagueModel model, ApplicationDbContext context) { var starter = context.LeagueModel.ToList().First(a => a.Name == model.Name); var playersSplit = starter.Players.Split(','); List <MatchupModel> matchup = new List <MatchupModel>(); List <PlayerModel> players = new List <PlayerModel>(); foreach (var elem in playersSplit) { foreach (var player in context.PlayerModel.ToList().Where(a => a.Name == elem)) { players.Add(player); } } var Event = new EventModel(); DateTime today = DateTime.Today; int daysUntilTuesday = ((int)DayOfWeek.Tuesday - (int)today.DayOfWeek + 7) % 7; Event.Date = today.AddDays(daysUntilTuesday); Event.Format = VotingModel.Formats.Standard; Event.LeagueId = starter.Id; Event.isFinished = false; var voting = new VotingModel(); voting.Event = Event; voting.IsOpened = true; context.VotingModel.Add(voting); context.EventModel.Add(Event); context.SaveChanges(); return(null); }
public ActionResult Vote(VoteBindingModel model) { if (model != null && this.ModelState.IsValid) { var userId = this.User.Identity.GetUserId(); var contest = this.ContestsData.Contests.Find(model.ContestId); if (contest == null) { this.AddToastMessage("Error", "Non existing contest!", ToastType.Error); var currentVotesNumber = this.ContestsData.Votes.All().Count(v => v.PhotoId == model.PhotoId && !v.Photo.IsDeleted); return this.Json(currentVotesNumber); } if (contest.IsFinalized && !contest.IsActive) { this.AddToastMessage("Warning", "You are not allowed to vote for this contest.", ToastType.Warning); var currentVotesNumber = this.ContestsData.Votes.All().Count(v => v.PhotoId == model.PhotoId && !v.Photo.IsDeleted); return this.Json(currentVotesNumber); } var photo = this.ContestsData.Photos.Find(model.PhotoId); if (photo == null) { this.AddToastMessage("Error", "Non existing photo!", ToastType.Error); var currentVotesNumber = this.ContestsData.Votes.All().Count(v => v.PhotoId == model.PhotoId && !v.Photo.IsDeleted); return this.Json(currentVotesNumber); } VotingModel votingModel = new VotingModel { Contest = contest, Photo = photo, UserId = userId }; VotingStrategy strategy = VotingFactory.CreateStrategy(contest.VotingType, votingModel); bool canVote = strategy.CanVote(); if (canVote) { var vote = new Vote { PhotoId = model.PhotoId, UserId = userId, ContestId = model.ContestId }; this.ContestsData.Votes.Add(vote); this.ContestsData.SaveChanges(); var newVotes = this.ContestsData.Votes.All() .Count(v => v.PhotoId == model.PhotoId && !v.Photo.IsDeleted); return this.Json(newVotes); } } var votes = this.ContestsData.Votes.All().Count(v => v.PhotoId== model.PhotoId && !v.Photo.IsDeleted); return this.Json(votes); }
public VotingHeaderPresenter(VotingModel item) { this.Model = item; }
public void Add(VotingModel voting, CommentVotingModel v) { gateway.AddCommentToVoting(voting.Id, v.Map <CommentVotingEntity>()); }