public ActionResult Add(int id)
        {
            //TODO: Validation
            var user = _users.GetUserFromUserIdentity(Request.GetIdentity());
            var comment = new Comment
                              {
                                  User = user,
                                  Time = DateTime.UtcNow,
                                  Text = Request.Form["comment"]
                              };

            _activities.Add(id, comment);
            return Redirect(string.Format("/idea/{0}#{1}", id, comment.Id));
        }
Пример #2
0
        public ActionResult Uservoice(string channel, string forumid, string apikey, bool trusted)
        {
            var client = new WebClient();
            var suggestions = GetSuggestions(client, channel, forumid, apikey, trusted);

            foreach (var s in suggestions)
            {
                string title = s.title;

                //If the idea exists, skip it
                if (_ideas.FindBy(i => i.Title == title).Any())
                    continue;

                string date = s.created_at;
                var idea = new Idea
                {
                    Title = title,
                    Description = s.text,
                    Time = DateTime.Parse(date.Substring(0, date.Length - 5)),
                };

                string status = string.Empty;
                switch ((string)s.state)
                {
                    case "approved":
                        status = "Active";
                        break;
                    case "closed":
                        status = s.status.key == "completed" ? "Completed" : "Declined";
                        break;
                    default:
                        status = "New";
                        break;
                }
                idea.Status = status;

                //Get the author, or create
                string name = s.creator.name;
                var existing = _users.FindBy(u => u.UserName == name).FirstOrDefault();
                if (existing != null)
                    idea.Author = existing;
                else
                {
                    idea.Author = NewUser(s.creator);
                    _users.Add(idea.Author);
                }

                _ideas.Add(idea);

                //Process all comments
                var comments = GetComments(client, (string)s.id, channel, forumid, apikey, trusted);
                foreach (var c in comments)
                {
                    string commentdate = c.created_at;
                    var comment = new Comment
                    {
                        Time = DateTime.Parse(commentdate),
                        Text = c.text
                    };

                    string commentname = c.creator.name;
                    existing = _users.FindBy(u => u.UserName == commentname).FirstOrDefault();
                    if (existing != null)
                        comment.User = existing;
                    else
                    {
                        comment.User = NewUser(c.creator);
                        _users.Add(comment.User);
                    }

                    _activities.Add(idea.Id, comment);
                }

                //Process all votes
                var votes = GetVotes(client, (string)s.id, channel, forumid, apikey, trusted);
                foreach (var v in votes)
                {
                    string votername = v.user.name;
                    string votesfor = v.votes_for;
                    int vote;
                    if (Int32.TryParse(votesfor, out vote))
                    {
                        existing = _users.FindBy(u => u.UserName == votername).FirstOrDefault();
                        if (existing != null)
                            _ideas.Vote(idea.Id, existing.Id, vote);
                        else
                        {
                            var author = NewUser(v.user);
                            _users.Add(author);
                            _ideas.Vote(idea.Id, author.Id, vote);
                        }
                    }
                }
            }

            return Redirect("/admin");
        }