public static void NewPoll(CSSDataContext db, string question, string[] options, DateTime expires) { var poll = new Poll() { Question = question, DateCreated = DateTime.Now, DateExpires = expires, LastRecalculation = DateTime.Now }; foreach (var po in options) { poll.PollOptions.Add(new PollOption() { Option = po, PollId = poll.Id, VoteCount = 0 }); } db.Polls.InsertOnSubmit(poll); db.SubmitChanges(); }
partial void DeletePoll(Poll instance);
partial void UpdatePoll(Poll instance);
partial void InsertPoll(Poll instance);
protected void btnSavePoll_Click(object sender, EventArgs e) { using (CSSDataContext db = new CSSDataContext()) { if (PollID == null) { Poll poll = new Poll() { DateCreated = DateTime.Now, DateExpires = DateTime.Parse(txtPollExpirationDate.Text), LastRecalculation = DateTime.Now, Question = txtQuestion.Text }; db.Polls.InsertOnSubmit(poll); db.SubmitChanges(); Response.Redirect("EditPoll.aspx?pollCreated=1&pollID=" + poll.Id, true); } else { Poll poll = db.Polls.FirstOrDefault(p => p.Id == PollID); if (poll == null) throw new Exception("Couldn't find poll: " + PollID); poll.DateExpires = DateTime.Parse(txtPollExpirationDate.Text); poll.Question = txtQuestion.Text; db.SubmitChanges(); lblErrorMessage.Text = "Poll updated."; pPollOptions.Visible = true; } } }
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(); } }