示例#1
0
        public ActionResult Create(int id)
        {
            Topic topic = entVote.Topics.Find(id);

            ViewBag.TopicTitle = topic.Topic1;
            ViewBag.TopicID = id.ToString();

            //ViewBag.TopicID = new SelectList(entVote.Topics, "TopicID", "Topic1");

            // If user is logged in, get UserID and set it to ViewBag to pass to the View.
            if (User.Identity.IsAuthenticated)
            {
                var userName = User.Identity.Name;
                Identity ident = new Identity();
                var userID = ident.GetUserID(userName);

                ViewBag.UserID = userID.ToString();
            }
            else
            {
                ViewBag.UserID = "0";
            }

            return View();
        }
示例#2
0
        public ActionResult Create([Bind(Include="TopicID,Topic1,TopicURL,Search,Tags,CategoryID,UserId,TimeStamp")] Topic topic)
        {
            if (ModelState.IsValid)
            {
                // If user is logged in, get UserID. To get to this point, user must be logged in.
                if (User.Identity.IsAuthenticated)
                {
                    var userName = User.Identity.Name;
                    Identity ident = new Identity();

                    topic.UserId = ident.GetUserID(userName);
                }
                else
                {
                    topic.UserId = 0;
                }

                SearchTools st = new SearchTools();

                topic.TopicURL = st.CreateSearchURL(topic.Topic1);
                topic.TimeStamp = DateTime.Now;

                entVote.Topics.Add(topic);
                entVote.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CategoryID = new SelectList(entVote.CategoryLists, "CategoryID", "Category", topic.CategoryID);
            return View(topic);
        }
示例#3
0
        public ActionResult TopicAnswers(int id)
        {
            // Get topic title for id.
            var topicTitle = (from t in entVote.Topics
                              where t.TopicID == id
                              select t.Topic1).FirstOrDefault();

            ViewBag.TopicTitle = topicTitle;
            ViewBag.TopicID = id;

            // Get base URL (e.g., http://www.eusVille.com)
            ViewBag.BaseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";

            // Get top 8 answers for topic based on TopicID.

            // listAnswers = (from a in entVote.Answers
            //               where a.TopicID == id
            //               orderby a.RatingScore descending
            //               select new {a.UserID, a.AnswerID, a.Detail, a.RatingScore}).Take(8);

            //var answers = (from a in entVote.Answers
            //               where a.TopicID == id
            //               orderby a.RatingScore descending
            //               select a).Take(8);

            //ViewBag.Count = answers.Count();

            // If user is logged in, get UserID and set it to ViewBag to pass to the View.
            var userID = 0;

            if (User.Identity.IsAuthenticated)
            {
                var userName = User.Identity.Name;
                Identity ident = new Identity();
                userID = (int)ident.GetUserID(userName);
            }

            ViewBag.UserID = userID.ToString();

            //else
            //{
            //    ViewBag.UserID = "0";
            //}

            //List<webUI.Models.GetTopicAnswers_Result> topicAnswersList = new List<webUI.Models.GetTopicAnswers_Result>();

            var answers = entVote.GetTopicAnswers(id, userID).ToList();

            //topicAnswersList.Add(answers);

            return View(answers);
        }
示例#4
0
        public string TopicGet(string Filter, string FilterData)
        {
            string jsonReturn = "";

            try
            {
                switch (Filter)
                {
                    case "AnswersGet":
                        {
                            int topicID = Convert.ToInt32(FilterData);

                            // Get topic title for id.
                            var topicTitle = (from t in entVote.Topics
                                              where t.TopicID == topicID
                                              select t.Topic1).FirstOrDefault();

                            ViewBag.TopicTitle = topicTitle;
                            ViewBag.TopicID = topicID;

                            // Get top 8 answers for topic based on TopicID.
                            //var answers = (from o in entVote.Answers
                            //               where o.TopicID == topicID
                            //               orderby o.RatingScore descending
                            //               select o).Take(8);

                            // If user is logged in, get UserID and set it to ViewBag to pass to the View.
                            var userID = 0;

                            if (User.Identity.IsAuthenticated)
                            {
                                var userName = User.Identity.Name;
                                Identity ident = new Identity();
                                userID = (int)ident.GetUserID(userName);
                                ViewBag.UserID = userID.ToString();
                            }
                            else
                            {
                                ViewBag.UserID = "0";
                            }

                            var answers = entVote.GetTopicAnswers(topicID, userID).ToList();

                            ViewBag.Count = answers.Count();

                            jsonReturn = JsonConvert.SerializeObject(answers, Formatting.Indented,
                                                new JsonSerializerSettings
                                                {
                                                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                                                });

                            break;
                        }
                    case "CommentsGet":
                        {
                            int answerID = Convert.ToInt32(FilterData);

                            using (eusVoteEntities entVote = new eusVoteEntities())
                            {
                                var comments = (from c in entVote.Comments
                                                where c.AnswerID == answerID
                                                select c).Take(5).ToArray();

                                jsonReturn = JsonConvert.SerializeObject(comments, Formatting.Indented,
                                                new JsonSerializerSettings
                                                {
                                                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                                                });
                            }

                            break;
                        }
                    default:
                        {
                            break;
                        }
                }

            }
            catch (Exception ex)
            {
                var seriesContent = new Dictionary<string, string>
                {
                    {"user" , "test"}, {"detail", ex.ToString()}, {"action", Filter},
                    {"errorLocation", "eusVote > TopicController > Topic > Get > " + Filter} , {"level", "high"}
                };

                jsonReturn = JsonConvert.SerializeObject(seriesContent);

                // Log error
                CommonController cont = new CommonController();
                cont.Common("ErrorHandle", jsonReturn);

                return jsonReturn;
            }

            return jsonReturn;
        }
示例#5
0
        // GET: eusVote/Home - Get a list of trending topics
        public ActionResult Index()
        {
            // If user is logged in, get UserID and set it to ViewBag to pass to the View.
            var userID = 0;

            if (User.Identity.IsAuthenticated)
            {
                var userName = User.Identity.Name;
                Identity ident = new Identity();
                userID = (int)ident.GetUserID(userName);
            }

            ViewBag.UserID = userID.ToString();

            var topics = db.Topics.Include(t => t.CategoryList);
            return View(topics.ToList());
        }