public ActionResult NewPoll(string question, string answers, bool? isAnonymous) { var p = new Poll() { CreatedAccountID = Global.AccountID, IsHeadline = true, QuestionText = question, IsAnonymous = isAnonymous == true, }; var db = new ZkDataContext(); foreach (var a in answers.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)) p.PollOptions.Add(new PollOption() { OptionText = a }); db.Polls.InsertOnSubmit(p); db.SubmitChanges(); return RedirectToAction("UserVotes", new { id = Global.AccountID }); }
public ActionResult NominateRole(int roleTypeID, string text, bool isRemoval = false, int? removalAccountID = null) { var db = new ZkDataContext(); var pollActive = Global.Account.PollsByRoleTargetAccountID.Any(x => x.ExpireBy > DateTime.UtcNow); if (pollActive) return Content("Poll already active, wait until it ends"); var rt = db.RoleTypes.Single(x => x.RoleTypeID == roleTypeID); if (!rt.IsClanOnly && GlobalConst.PlanetWarsMode == PlanetWarsModes.AllOffline) return Content("Round over, no nominations can be made"); if (rt.RestrictFactionID != null && rt.RestrictFactionID != Global.FactionID) throw new ApplicationException("Invalid faction"); if (!rt.IsClanOnly && Global.FactionID == 0) throw new ApplicationException("No faction"); if (!rt.IsClanOnly && rt.Faction.IsDeleted) throw new ApplicationException("Disabled faction"); if (rt.IsClanOnly && Global.ClanID == 0) throw new ApplicationException("No clan"); if (!rt.IsVoteable) throw new ApplicationException("Cannot be voted"); int targetID = Global.AccountID; if (isRemoval) { var target = db.Accounts.Single(x => x.AccountID == removalAccountID); if (Global.Account.CanVoteRecall(target, rt)) { targetID = removalAccountID.Value; } else { return Content("Cannot recall him/her"); } } var p = new Poll() { CreatedAccountID = Global.AccountID, RoleTargetAccountID = targetID, ExpireBy = DateTime.UtcNow.AddDays(rt.PollDurationDays), IsAnonymous = true, IsHeadline = true, RoleIsRemoval = isRemoval, RoleType = rt, RestrictClanID = rt.IsClanOnly ? Global.Account.ClanID : null, RestrictFactionID = rt.IsClanOnly ? null : Global.Account.FactionID, QuestionText = text }; p.PollOptions.Add(new PollOption() { OptionText = "Yes" }); p.PollOptions.Add(new PollOption() { OptionText = "No" }); db.Polls.InsertOnSubmit(p); db.SubmitChanges(); return RedirectToAction("Detail", "Users", new { id = Global.AccountID }); }