public async Task <FeedPost> UploadPollPost(FeedPoll poll) { using (var conn = new MySqlConnection(connString)) //New connection { await conn.OpenAsync(); //Waits for connection to open using (var cmd = new MySqlCommand($"INSERT INTO feed_post VALUES({0}, 'poll', {poll.posterId}, {poll.subjectId}, '{poll.datePosted.ToString("yyyy-MM-dd hh:mm:ss")}', " + $"{Convert.ToBoolean(poll.isAnnouncement)}, {Convert.ToBoolean(poll.isDeleted)});", conn)) //Inserts post into feed_post { await cmd.ExecuteNonQueryAsync(); //Executes that command int id = (int)cmd.LastInsertedId; //Gets the last inserted auto incremented id using (var cmd2 = new MySqlCommand($"INSERT INTO feed_poll VALUES({id}, '{poll.PollQuestion}');", conn)) await cmd2.ExecuteNonQueryAsync(); //Inserts value into feed_poll values string answersCommand = ""; //Sets up an empty string foreach (FeedAnswer answer in poll.Answers) //For each answer in the answers array { // Add to the answersCommand string, insert each feed_poll_answer row answersCommand += $" INSERT INTO feed_poll_answer VALUES({0}, {id}, '{answer.Answer}');"; } using (var cmd3 = new MySqlCommand(answersCommand, conn)) //Executes all the commands above await cmd3.ExecuteNonQueryAsync(); return(await GetPostById(id)); //Returns the FeedPoll object } } }
public async Task <FeedPost> GetPostById(int postid) { using (var conn = new MySqlConnection(connString)) //Creates a temporary new Connectio { await conn.OpenAsync(); //Waits for connection to open using (var cmd = new MySqlCommand($"SELECT * FROM feed_post WHERE `PostId`={postid};", conn)) //Select command to get the row of the id using (var reader = await cmd.ExecuteReaderAsync()) //Executes the above command { if (await reader.ReadAsync()) //If any row was returned { FeedPost post = new FeedPost //Create new FeedPost object from our returned values { postId = Convert.ToInt32(reader["postId"]), posterId = Convert.ToInt32(reader["posterId"]), postType = reader["postType"].ToString(), subjectId = Convert.ToInt32(reader["subjectId"]), datePosted = Convert.ToDateTime(reader["datePosted"]), isAnnouncement = Convert.ToBoolean(reader["isAnnouncement"]), isDeleted = Convert.ToBoolean(reader["isDeleted"]), poster = await new UserTasks().GetUserById(Convert.ToInt32(reader["posterId"]), flatten: true), likes = await GetAllLikesForPost(Convert.ToInt32(reader["postId"])) }; string json = Json.Stringify(post); //Convert the above object into a json string switch (post.postType) //What to do for each post type { case "text": //IF it is a text post FeedTextPost tPost = Json.Parse <FeedTextPost>(json); //Convert the above json into a FeedTextPost object tPost = await AddTextPostValues(tPost); //Create a new object from the above one, with our additional text values return(tPost); //return it case "media": FeedMediaPost mPost = Json.Parse <FeedMediaPost>(json); //Convert the abve json intoa FeedMediaPost object mPost = await AddMediaPostValues(mPost); //Create a new object from the above, with our additional media values return(mPost); //return it case "poll": //If it is a poll FeedPoll pPost = Json.Parse <FeedPoll>(json); //Convert above json to a FeedPoll object pPost = await AddPollPostValues(pPost); //Create a new object from the above, including additional values return(pPost); //return it case "quiz": FeedQuiz fPost = Json.Parse <FeedQuiz>(json); //Convert json into FeedQuiz object fPost = await AddBasicQuizValues(fPost); //Adds quiz values return(fPost); //return it default: return(null); //If the switch statement fails, return nothing. } } } return(null); //If no row is returned, return nothing. } }
public PollWrapper(FeedPoll poll) { Voted = poll.IsUserVote(SecurityContext.CurrentAccount.ID.ToString()); if (Voted) { //Get results } StartDate = (ApiDateTime)poll.StartDate; EndDate = (ApiDateTime)poll.EndDate; PollType = poll.PollType; Votes = poll.Variants.Select(x => new VoteWrapper() { Id = x.ID, Name = x.Name, Votes = poll.GetVariantVoteCount(x.ID) }); }
public CheckEmptyContentResult IsEmpty() { try { var storage = FeedStorageFactory.Create(); var polls = storage.GetFeeds(FeedType.Poll, Guid.Empty, 1, 0); if (0 < polls.Count) { poll = storage.GetFeed(polls[0].Id) as FeedPoll; } } catch { } if (poll == null) { return(CheckEmptyContentResult.NotEmpty); } return(CheckEmptyContentResult.Empty); }
public async Task <FeedPoll> AddPollPostValues(FeedPoll post) { using (var conn = new MySqlConnection(connString)) //New connection { await conn.OpenAsync(); //Waits to open using (var cmd = new MySqlCommand($"SELECT * FROM feed_poll WHERE `PostId`={post.postId};", conn)) //^ Selects all data from feed_poll for our post using (var reader = await cmd.ExecuteReaderAsync()) //reads the data { if (await reader.ReadAsync()) //IF we found anything { post.PollQuestion = reader["pollQuestion"].ToString(); post.Answers = await AddPollAnswers(post.postId); return(post); //Add the poll attributes to the post object } } return(null); //else return nothing } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { var storage = FeedStorageFactory.Create(); var polls = storage.GetFeeds(FeedType.Poll, Guid.Empty, 1, 0); if (0 < polls.Count) { poll = storage.GetFeed(polls[0].Id) as FeedPoll; } } catch { } if (poll == null) { return; } bool isMakeVote = TenantUtil.DateTimeNow() <= poll.EndDate && !poll.IsUserVote(SecurityContext.CurrentAccount.ID.ToString()); pollForm.VoteHandlerType = typeof(PollVoteHandler); pollForm.Answered = !isMakeVote || SecurityContext.DemoMode || (SetupInfo.WorkMode == WorkMode.Promo); pollForm.Name = poll.Caption.HtmlEncode(); pollForm.PollID = poll.Id.ToString(CultureInfo.CurrentCulture); pollForm.Singleton = (poll.PollType == FeedPollType.SimpleAnswer); pollForm.AdditionalParams = poll.Id.ToString(CultureInfo.CurrentCulture); foreach (var variant in poll.Variants) { pollForm.AnswerVariants.Add(new PollForm.AnswerViarint() { ID = variant.ID.ToString(CultureInfo.CurrentCulture), Name = variant.Name, VoteCount = poll.GetVariantVoteCount(variant.ID) }); } }
public void PollTest() { var userId = SecurityContext.CurrentAccount.ID.ToString(); var poll = new FeedPoll(); poll.Caption = "Poll1"; poll.Variants.Add(new FeedPollVariant() { Name = "v1" }); poll.Variants.Add(new FeedPollVariant() { Name = "v2" }); poll.Variants.Add(new FeedPollVariant() { Name = "v3" }); feedStorage.SaveFeed(poll, TODO, TODO); poll.Variants.RemoveAt(2); feedStorage.SaveFeed(poll, TODO, TODO); poll.Variants.Add(new FeedPollVariant() { Name = "v3" }); feedStorage.SaveFeed(poll, TODO, TODO); poll = new FeedPoll(); poll.Caption = "Poll2"; poll.PollType = FeedPollType.MultipleAnswer; poll.Variants.Add(new FeedPollVariant() { Name = "v1" }); feedStorage.SaveFeed(poll, TODO, TODO); var polls = feedStorage.GetFeeds(FeedType.Poll, Guid.Empty, 0, 0); Assert.AreEqual(2, polls.Count); var poll1 = (FeedPoll)feedStorage.GetFeed(polls[1].Id); Assert.AreEqual(3, poll1.Variants.Count); Assert.AreEqual("v1", poll1.Variants[0].Name); feedStorage.PollVote(userId, new[] { poll1.Variants[0].ID, poll1.Variants[1].ID }); var poll2 = (FeedPoll)feedStorage.GetFeed(polls[0].Id); Assert.AreEqual(FeedPollType.MultipleAnswer, poll2.PollType); Assert.AreEqual(1, poll2.Variants.Count); poll1 = (FeedPoll)feedStorage.GetFeed(poll1.Id); Assert.AreEqual(1, poll1.GetVariantVoteCount(poll1.Variants[0].ID)); Assert.AreEqual(1, poll1.GetVariantVoteCount(poll1.Variants[1].ID)); Assert.AreEqual(0, poll1.GetVariantVoteCount(poll1.Variants[2].ID)); Assert.IsTrue(poll1.IsUserVote(userId)); Assert.IsFalse(poll2.IsUserVote(userId)); feedStorage.RemoveFeed(poll1.Id); feedStorage.RemoveFeed(poll2.Id); }
protected void Page_Load(object sender, EventArgs e) { if (SetupInfo.WorkMode == WorkMode.Promo) { Response.Redirect(FeedUrls.MainPageUrl, true); } if (!CommunitySecurity.CheckPermissions(NewsConst.Action_Add)) { Response.Redirect(FeedUrls.MainPageUrl, true); } Breadcrumb.Add(new BreadCrumb() { Caption = NewsResource.NewsBreadCrumbs, NavigationUrl = VirtualPathUtility.ToAbsolute("~/products/community/modules/news/") }); if (Info.HasUser) { Breadcrumb.Add(new BreadCrumb() { Caption = Info.User.DisplayUserName(false), NavigationUrl = string.Format(CultureInfo.CurrentCulture, "{0}?uid={1}", VirtualPathUtility.ToAbsolute("~/products/community/modules/news/"), Info.UserId) }); } var storage = FeedStorageFactory.Create(); Feed feed = null; long docID = 0; if (!string.IsNullOrEmpty(Request["docID"]) && long.TryParse(Request["docID"], out docID)) { feed = storage.GetFeed(docID); } if (!IsPostBack) { _errorMessage.Text = ""; if (feed != null) { if (!CommunitySecurity.CheckPermissions(feed, NewsConst.Action_Edit)) { Response.Redirect(FeedUrls.MainPageUrl, true); } FeedId = docID; FeedPoll pollFeed = feed as FeedPoll; if (pollFeed != null) { _pollMaster.QuestionFieldID = "feedName"; var question = pollFeed; _pollMaster.Singleton = (question.PollType == FeedPollType.SimpleAnswer); _pollMaster.Name = feed.Caption; _pollMaster.ID = question.Id.ToString(CultureInfo.CurrentCulture); foreach (var variant in question.Variants) { _pollMaster.AnswerVariants.Add(new ASC.Web.Controls.PollFormMaster.AnswerViarint() { ID = variant.ID.ToString(CultureInfo.CurrentCulture), Name = variant.Name }); } } } else { _pollMaster.QuestionFieldID = "feedName"; } } else { SaveFeed(); } if (feed != null) { Breadcrumb.Add(new BreadCrumb() { Caption = feed.Caption, NavigationUrl = VirtualPathUtility.ToAbsolute("~/products/community/modules/news/") + "?docid=" + docID + Info.UserIdAttribute }); Breadcrumb.Add(new BreadCrumb() { Caption = NewsResource.NewsEditBreadCrumbsPoll, NavigationUrl = VirtualPathUtility.ToAbsolute("~/products/community/modules/news/editpoll.aspx") + "?docid=" + docID + Info.UserIdAttribute }); lbCancel.NavigateUrl = VirtualPathUtility.ToAbsolute("~/products/community/modules/news/") + "?docid=" + docID + Info.UserIdAttribute; } else { Breadcrumb.Add(new BreadCrumb() { Caption = NewsResource.NewsAddBreadCrumbsPoll, NavigationUrl = VirtualPathUtility.ToAbsolute("~/products/community/modules/news/editpoll.aspx") + (string.IsNullOrEmpty(Info.UserIdAttribute) ? string.Empty : "?" + Info.UserIdAttribute.Substring(1)) }); lbCancel.NavigateUrl = VirtualPathUtility.ToAbsolute("~/products/community/modules/news/") + (string.IsNullOrEmpty(Info.UserIdAttribute) ? string.Empty : "?" + Info.UserIdAttribute.Substring(1)); } this.Title = HeaderStringHelper.GetPageTitle(Resources.NewsResource.AddonName, Breadcrumb); }
public async Task <IActionResult> UploadPoll([FromBody] FeedPoll poll) { return(Ok(await new FeedTasks().UploadPollPost(poll))); }