예제 #1
0
        public ActionResult Comments(int id)
        {
            IEnumerable<CommentModel> comments;

            using (eusCommonEntities entCommon = new eusCommonEntities())
            {
                using (eusVoteEntities entVote = new eusVoteEntities())
                {
                    var listUsers = new List<AspNetUser>(entCommon.AspNetUsers);
                    var listComments = new List<Comment>(entVote.Comments);

                    // Do a join to listUsers to get the UserName
                    comments = (from c in listComments
                                join u in listUsers on c.UserID equals u.UserID
                                where (c.AnswerID == id)
                                select new CommentModel
                                {
                                    Author = u.UserName,
                                    Text = c.Comment1,
                                    UserID = u.UserID
                                });
                }
            }
            return Json(comments, JsonRequestBehavior.AllowGet);
        }
예제 #2
0
        // id is answerID (e.g., 10 for Minato Sushi Restaurant)
        // GET: Comment View
        public ActionResult Index(int id)
        {
            // If user is logged in, get UserID and set it to ViewBag to pass to the View.
            if (User.Identity.IsAuthenticated)
            {
                using (eusCommonEntities entCommon = new eusCommonEntities())
                {
                    var userName = User.Identity.Name;

                    var userID = (from i in entCommon.AspNetUsers
                                  where i.UserName == User.Identity.Name
                                  select i.UserID).FirstOrDefault();

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

            using (eusVoteEntities entVote = new eusVoteEntities())
            {
                var answer = (from o in entVote.Answers
                                   where o.AnswerID == id
                                   select new {o.TopicID, o.Title}).FirstOrDefault();

                ViewBag.AnswerTitle = answer.Title;

                var topic = (from t in entVote.Topics
                             where t.TopicID == answer.TopicID
                             select new { t.Topic1, t.TopicURL }).FirstOrDefault();

                // Topic title and id to be passed into comments view to create ReturnURL
                ViewBag.TopicTitle = topic.Topic1;
                ViewBag.TopicTitleURL = topic.TopicURL;
                ViewBag.TopicID = answer.TopicID.ToString();
            }

            ViewBag.AnswerID = id.ToString();

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

            IEnumerable<CommentModel> comments;

            using (eusCommonEntities entCommon = new eusCommonEntities())
            {
                using (eusVoteEntities entVote = new eusVoteEntities())
                {
                    var listUsers = new List<AspNetUser>(entCommon.AspNetUsers);
                    var listComments = new List<Comment>(entVote.Comments);

                    // Do a join to listUsers to get the UserName
                    comments = (from c in listComments
                                join u in listUsers on c.UserID equals u.UserID
                                where (c.AnswerID == id)
                                select new CommentModel
                                {
                                    Author = u.UserName,
                                    Text = c.Comment1,
                                    UserID = u.UserID
                                });
                }
            }

            return View(comments);
        }
예제 #3
0
        // POST
        public void Common(string Filter, string FilterData)
        {
            string jsonReturn = "";

            try
            {
                switch (Filter)
                {
                    case "ErrorHandle":  // log error into eusCommon.dbo.Admin_ErrorLog
                        {
                            // Parse out JSON data
                            JObject o = JObject.Parse(FilterData);

                            string user = o.SelectToken("user").ToString();
                            string detail =  o.SelectToken("detail").ToString();
                            string action =  o.SelectToken("action").ToString();
                            string errorLocation =  o.SelectToken("errorLocation").ToString();
                            string level = o.SelectToken("level").ToString();

                            if (level == "high")
                            {
                                // email admin to notify !!
                            }

                            using (eusCommonEntities ent = new eusCommonEntities())
                            {
                                Admin_ErrorLog log = new Admin_ErrorLog();

                                log.User = user;
                                log.Action = action;
                                log.Details = detail;
                                log.ErrorLocation = errorLocation;
                                log.Level = level;
                                log.Timestamp = DateTime.Now;
                                log.IsOpen = true;

                                ent.Admin_ErrorLog.Add(log);
                                ent.SaveChanges();

                                break;
                            }
                        }

                    case "Email":
                        {
                            // Send email !
                            break;
                        }

                    default:
                        {
                            //var seriesContent = new Dictionary<string, string>
                            //        {
                            //            {"error", "true"} , {"message", "Controller: eusVote_Topic.Topic doesn't have matching filter for filter = " + Filter }
                            //        };

                            //jsonReturn = JsonConvert.SerializeObject(seriesContent);
                            break;
                        }
                }
            }
            catch (Exception ex)
            {
                var seriesContent = new Dictionary<string, string>
                {
                    {"user", "inside catch"}, {"detail", ex.ToString()}, {"action", "Failed to log error."},
                    {"errorLocation", "CommonController > ErrorHandle "}
                };

                jsonReturn = JsonConvert.SerializeObject(seriesContent);

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

            //return jsonReturn;
        }