public int UpdatePollOption(int pollID, int? pollOptionId, string optionText) { CheckAccess(); using (CSSDataContext db = new CSSDataContext()) { if (pollOptionId == null) { PollOption newPollOption = new PollOption() { Option = optionText, VoteCount = 0 }; Poll poll = db.Polls.FirstOrDefault(p => p.Id == pollID); if (poll == null) throw new Exception("Couldn't get poll: " + pollID); poll.PollOptions.Add(newPollOption); db.SubmitChanges(); return newPollOption.Id; } else { PollOption pollOption = db.PollOptions.FirstOrDefault(p => p.Id == pollOptionId); if (pollOption == null) throw new Exception("Couldn't find poll option: " + pollOptionId); pollOption.Option = optionText; return pollOptionId.Value; } } }
private void attach_PollOptions(PollOption entity) { this.SendPropertyChanging(); entity.Poll = this; }
private void detach_PollOptions(PollOption entity) { this.SendPropertyChanging(); entity.Poll = null; }
partial void DeletePollOption(PollOption instance);
partial void UpdatePollOption(PollOption instance);
partial void InsertPollOption(PollOption instance);
protected void btnSavePollOption_Click(object sender, EventArgs e) { //string pollOptionText = txtPollOption.Value; using (CSSDataContext db = new CSSDataContext()) { int editingPollOptionID = Int32.Parse(txtEditingPollOptionID.Value); PollOption pollOption; var poll = db.Polls.FirstOrDefault(p => p.Id == PollID); if (poll == null) throw new Exception("Couldn't find poll: " + PollID); if (editingPollOptionID == 0) { pollOption = new PollOption(); pollOption.VoteCount = 0; poll.PollOptions.Add(pollOption); } else { pollOption = db.PollOptions.FirstOrDefault(p => p.Id == editingPollOptionID); if (pollOption == null) throw new Exception("Couldn't get poll option: " + editingPollOptionID); } if (txtPollOptionValue.Value.Length > 70) pollOption.Option = txtPollOptionValue.Value.Substring(0, 70); else pollOption.Option = txtPollOptionValue.Value; db.SubmitChanges(); } BindData(); }
private void CreateTestData(out Login login1, out Login login2, out Login login3) { using (var db = new CSSDataContext()) { ClearDataForCallsign("User1"); ClearDataForCallsign("User2"); ClearDataForCallsign("User3"); //ClearDataForCallsign("User4"); login1 = CreateUser("User1", "Password1", "*****@*****.**", 10); login2 = CreateUser("User2", "Password2", "*****@*****.**", 20); login3 = CreateUser("User3", "Password3", "*****@*****.**", 13); // User1 and 3 should have some duplicate IPs //login4 = CreateUser("User4", "Password4", "*****@*****.**"); BanType banType = db.BanTypes.FirstOrDefault(); if (banType == null) { var banClass = new BanClass() { Name = "Auto" }; db.BanClasses.InsertOnSubmit(banClass); db.SubmitChanges(); banType = new BanType() { //BanClass = banClass, BanClassId = banClass.Id, BaseTimeInMinutes = 30, Description = "Harassment / Threats", IsIncremental = true, RocNumber = 1 }; db.BanTypes.InsertOnSubmit(banType); db.SubmitChanges(); } db.Bans.InsertOnSubmit(new Ban() { BannedByLoginId = 1, //BanType = banType, BanTypeId = banType.Id, DateCreated = DateTime.Now, DateExpires = DateTime.Now.AddDays(1), InEffect = true, Reason = "Pork Muffins!", LoginId = login2.Id }); db.SubmitChanges(); db.Bans.InsertOnSubmit(new Ban() { BannedByLoginId = 1, //BanType = banType, BanTypeId = banType.Id, DateCreated = DateTime.Now.AddDays(-30), DateExpires = DateTime.Now.AddDays(-29), InEffect = false, Reason = "Old ban.", LoginId = login2.Id, }); db.SubmitChanges(); MachineRecordType machineRecordType = db.MachineRecordTypes.FirstOrDefault(); if (machineRecordType == null) { machineRecordType = new MachineRecordType() { Id = 1, Name = "Network" }; db.MachineRecordTypes.InsertOnSubmit(machineRecordType); machineRecordType = new MachineRecordType() { Id = 2, Name = "HardDisk" }; machineRecordType = new MachineRecordType() { Id = 3, Name = "EDID" }; machineRecordType = new MachineRecordType() { Id = 4, Name = "Serial" }; machineRecordType = new MachineRecordType() { Id = 5, Name = "Misc" }; db.MachineRecordTypes.InsertOnSubmit(machineRecordType); db.SubmitChanges(); } db.MachineRecords.InsertOnSubmit(new MachineRecord() { DeviceType = Allegiance.CommunitySecuritySystem.Common.Envelopes.AuthInfo.DeviceType.HardDisk, Identifier = "1234567890", LoginId = login3.Id, RecordTypeId = (int)Allegiance.CommunitySecuritySystem.Common.Envelopes.AuthInfo.DeviceType.HardDisk }); db.SubmitChanges(); db.MachineRecords.InsertOnSubmit(new MachineRecord() { DeviceType = Allegiance.CommunitySecuritySystem.Common.Envelopes.AuthInfo.DeviceType.Serial, Identifier = "ABCDEFGHIJKLMNOP", LoginId = login3.Id, RecordTypeId = (int)Allegiance.CommunitySecuritySystem.Common.Envelopes.AuthInfo.DeviceType.Serial }); db.SubmitChanges(); Poll poll = db.Polls.FirstOrDefault(); PollOption pollOption1 = null; if (poll == null) { poll = new Poll() { DateCreated = DateTime.Now, DateExpires = DateTime.Now.AddDays(30), Question = "This is the question.", LastRecalculation = DateTime.Now }; db.Polls.InsertOnSubmit(poll); db.SubmitChanges(); pollOption1 = new PollOption() { Option = "Option 1", PollId = poll.Id, VoteCount = 0 }; db.PollOptions.InsertOnSubmit(pollOption1); db.SubmitChanges(); } else { pollOption1 = db.PollOptions.First(); } db.PollVotes.InsertOnSubmit(new PollVote() { LoginId = login3.Id, PollOptionId = pollOption1.Id }); db.SubmitChanges(); } }