Пример #1
0
        public ActionResult PostAnswer(int? id, string msg)
        {
            if (id != null)
            {
                ViewBag.id = id.Value;
                if (Request.IsAuthenticated)
                {
                    var authuserId = _db.ForumUser.Single(m => m.UserName.Equals(User.Identity.Name)).UserId;
                   
          

                    if (msg != "")
                    {
                        if (msg.Length >= 10)
                        {
                            var ms = "";
                            var wdb = new WordDbContext();
                  
                            var sensitiveWods = wdb.Words.Select(m => m.SensitiveWord);
                            var strList = new List<SensitiveWordsViewModel>();

                            var convt = msg.ToLower();
                            foreach (var str in sensitiveWods)
                            {
                                if (!convt.Contains(str.ToLower())) continue;
                                var sensitive = new SensitiveWordsViewModel {SensitiveWords = str};
                                strList.Add(sensitive);
                                ViewBag.senWordsMsg = 11;

                                ms = str;
                            }



                            if (ms == "")
                            {

                                var checKIsReplyExist = _db.Answers.Any(m => m.UserId.Equals(authuserId) && m.QuestionId.Equals(id.Value));
                                if (!checKIsReplyExist)
                                {
                                    var ans = new Answers
                                    {
                                        UserId = authuserId,
                                        AnsweredTimeDate = DateTime.Now,
                                        QuestionId = id.Value,
                                        Answer = msg,
                                        Rating = 0
                                    };

                                    _db.Answers.Add(ans);
                                    _db.SaveChanges();

                                    var u
                                        = _db.PostInformation.SingleOrDefault(m => m.UserId.Equals(authuserId));
                                    if (u != null)
                                    {
                                        var posId = u.PostId;
                                        var v = _db.PostInformation.Find(posId).TotalAnsPost;
                                        if (v != null)
                                        {
                                            var prevPosts = v.Value;
                                            var pi = _db.PostInformation.Find(posId);


                                            pi.TotalAnsPost = prevPosts + 1;

                                            _db.Entry(pi).State = EntityState.Modified;
                                        }
                                    }
                                    _db.SaveChanges();
                                    ViewData["c"] = 4;
                                    ViewBag.operation = 2;
                                    ViewBag.checkCrontroller = 2;
                                    UpdateAns(id.Value);
                                    DisplayQuesAnsComments(id.Value);
                                }
                                else
                                {

                                    ViewData["PostNotAllowedId"] = 1;
                                }
                            }

                            TempData["QiComm"] = id;
                        

                            DisplayQuesAnsComments(id.Value);
                            ViewBag.operation = 2;
                            ViewBag.checkCrontroller = 2;
                            IEnumerable<SensitiveWordsViewModel> s = strList;
                            ViewData["s"] = s;

                        }
                        else
                        {

                            TempData["QiComm"] = id;


                            DisplayQuesAnsComments(id.Value);
                            ViewBag.operation = 2;
                            ViewBag.checkCrontroller = 2;
                            ViewData["ReqMsg"] = 3;
                            ViewData["Mess"] = "* Answers should not contain less than 10 chracters";

                        }
                    }
                    else
                    {
                        TempData["AnsId"] = id.Value;
                        DisplayQuesAnsComments(id.Value);
                        ViewBag.operation = 2;
                        ViewBag.checkCrontroller = 2;
                        ViewData["ReqMsg"] = 3;
                        ViewData["Mess"] = "*  Empty Field not allowed!.Please Write Your Answer";
                    }


             
                    return View("_PostAnswer");
                


                }
                else
                {

                
             
               
                    DisplayQuesAnsComments(id.Value);
             

                    ViewData["c"] = 5;
              
                    ViewBag.operation = 2;
                    ViewBag.checkCrontroller = 2;
                    TempData["HomeAnsPostController"] = 2;




                }


                TempData["QiComm"] = id;
                TempData["AnsId"] = id;

                DisplayQuesAnsComments(id.Value);
            }
            ViewBag.operation = 2;
            ViewBag.checkCrontroller = 2;
            return View("_PostAnswer");





        }
Пример #2
0
        public ActionResult PostComment(string msg, RatingViewModel model, int? id)
        {
            ViewBag.ansId = id;
            var v = _db.Answers.FirstOrDefault(m => m.AnswerId.Equals(id.Value));
            if (v != null)
                ViewBag.quesTionid = v.QuestionId;

            ViewBag.id = id;
           

            TempData["HPostController"] = 7;


            var strList = new List<SensitiveWordsViewModel>();
            var wdb = new WordDbContext();


            if (Request.IsAuthenticated)
            {
                var u = _db.ForumUser.SingleOrDefault(m => m.UserName.Equals(User.Identity.Name));
                if (u != null)
                {
                    var userId = u.UserId;
             



       
                    if (true)
                    {
                           
                        var authUserId =
                            u.UserId;
                        var w = _db.Answers.SingleOrDefault(m => m.AnswerId.Equals(id.Value));
                        if (w != null)
                        {
                            var thisAnsUserId = w.UserId;
                            if (authUserId == thisAnsUserId)
                            {
                                ViewData["EnableEdit"] = 1;
                            }
                        }


                        if (msg != "")
                        {


                            var ms = "";
                       
                            var sensitiveWods = wdb.Words.Select(m => m.SensitiveWord);
                    

                            var convt = msg.ToLower();
                            foreach (var str in sensitiveWods)
                            {
                                if (!convt.Contains(str.ToLower())) continue;
                                var sensitive = new SensitiveWordsViewModel {SensitiveWords = str};
                                strList.Add(sensitive);
                                ViewBag.senWordsMsg = 11;

                                ms = str;
                            }

                            IEnumerable<SensitiveWordsViewModel> s = strList;
                            ViewData["s"] = s;

                            ViewData["op"] = 1;
                            if (ms == "")
                            {
                               

                                _comment.CommentMsg = msg;
                                _comment.UserId = userId;
                                if (id != null)
                                {
                                    _comment.AnswerId = id.Value;
                                    _comment.PostedDateTime = DateTime.Now;
                                    _db.Comment.Add(_comment);
                                    _db.SaveChanges();
                                    var t = _db.PostInformation.SingleOrDefault(m => m.UserId.Equals(userId));
                                    if (t != null)
                                    {
                                        var posId = t.PostId;
                                        var totalCommentPost = _db.PostInformation.Find(posId).TotalCommentPost;
                                        if (totalCommentPost != null)
                                        {
                                            var prevPosts = totalCommentPost.Value;
                                            var pi = _db.PostInformation.Find(posId);


                                            pi.TotalCommentPost = prevPosts + 1;

                                            _db.Entry(pi).State = EntityState.Modified;
                                        }
                                    }
                                    _db.SaveChanges();
                                    ViewBag.emptyBox = 1;
                                    UpdateTotalComments(id.Value);
                                    DisplayAnswerAndPostedUserInfo(id.Value);
                                    DisplayComments(id.Value);
                                }
                            }
                            if (id != null)
                            {
                                DisplayAnswerAndPostedUserInfo(id.Value);
                                DisplayComments(id.Value);
                            }
                        }
                        else
                        {
                            if (id != null)
                            {
                                DisplayAnswerAndPostedUserInfo(id.Value);
                                DisplayComments(id.Value);
                            }
                            ViewData["op"] = 1;
                            ViewData["ReqMsg"] = 1;
                            ViewBag.errormsg = "* You must Write Something! to Post  comment";

                          
                        }


                    }
                    
                }
            }
            else
            {
                if (id != null)
                {
                    DisplayAnswerAndPostedUserInfo(id.Value);
                    DisplayComments(id.Value);
                }
                ViewData["op"] = 1;
                ViewData["ReqMsg"] = 1;
                ViewData["c"] = 5;

          

            }




            try
            {


                var totalScore = _db.Rating.Where(m => m.AnswerId.Equals(id.Value)).Sum(m => m.RateScore);
                var totalRater = _db.Rating.Count(m => m.AnswerId.Equals(id.Value));
                var avgScore = (double)totalScore / totalRater;
                ViewData["raiting"] = avgScore;
            }
            catch (Exception e) { }



           

          


            return View("Comments",model);
        }
        public ActionResult PostAnswerForAnsweredQuestion(int? id, string msg)
        {

            int tempId = db.TemQuesIdModels.SingleOrDefault(m => m.Id.Equals(1)).TempQuesId;

            if (Request.IsAuthenticated)
            {
                if (id == null)
                {

                    if (msg != "")
                    {
                        if (msg.Length >= 10)
                        {

                            string ms = "";
                            WordDbContext wdb = new WordDbContext();
                            var sensitiveWods = wdb.Words.Select(m => m.SensitiveWord);
                            List<SensitiveWordsViewModel> strList = new List<SensitiveWordsViewModel>();
                            ViewBag.fc = 2;
                            string convt = msg.ToLower();
                            foreach (string str in sensitiveWods)
                            {
                                if (convt.Contains(str))
                                {
                                    SensitiveWordsViewModel sensitive = new SensitiveWordsViewModel();
                                    sensitive.SensitiveWords = str;
                                    strList.Add(sensitive);
                                    ViewBag.senWordsMsg = 11;
                                    ms = str;

                                }





                            }
                            IEnumerable<SensitiveWordsViewModel> s = strList;
                            ViewData["s"] = s;

                            if (ms == "")
                            {
                                Answers ans = new Answers();
                                int authuserId = _db.ForumUser.Single(m => m.UserName.Equals(User.Identity.Name)).UserId;
                                ans.UserId = authuserId;
                                ans.AnsweredTimeDate = DateTime.Now;
                                ans.QuestionId = tempId;
                                ans.Answer = msg;
                                ans.Rating = 0;
                                _db.Answers.Add(ans);
                                _db.SaveChanges();

                                ViewData["c"] = 4;
                                ViewBag.operation = 2;
                                ViewBag.checkCrontroller = 2;
                                UpdateAns(tempId);
                                DisplayQuesAnsComments(tempId);

                            }


                        }
                        else
                        {

                            TempData["AnsId"] = tempId;
                            DisplayQuesAnsComments(tempId);
                            ViewBag.operation = 1;
                            ViewBag.checkCrontroller = 1;
                            ViewData["ReqMsg"] = 3;
                            ViewData["Mess"] = "* Answers should not contain less than 10 chracters";

                        }

                    }
                    else
                    {
                        TempData["AnsId"] = tempId;
                        DisplayQuesAnsComments(tempId);
                        ViewBag.operation = 1;
                        ViewBag.checkCrontroller = 1;
                        ViewData["ReqMsg"] = 3;
                        ViewData["Mess"] = "*  Empty Field not allowed!.Please Write Your Answer";

                        return View("_PostAnswer");
                    }

                }
                else
                {

                    if (msg != "")
                    {
                        if (msg.Length >= 10)
                        {

                            string ms = "";
                            WordDbContext wdb = new WordDbContext();
                            var sensitiveWods = wdb.Words.Select(m => m.SensitiveWord);
                            List<SensitiveWordsViewModel> strList = new List<SensitiveWordsViewModel>();

                            string convt = msg.ToLower();
                            foreach (string str in sensitiveWods)
                            {
                                if (convt.Contains(str))
                                {
                                    SensitiveWordsViewModel sensitive = new SensitiveWordsViewModel();
                                    sensitive.SensitiveWords = str;
                                    strList.Add(sensitive);
                                    ViewBag.senWordsMsg = 11;
                                    ms = str;

                                }





                            }
                            IEnumerable<SensitiveWordsViewModel> s = strList;
                            ViewData["s"] = s;
                            if (ms == "")
                            {

                                Answers ans = new Answers();
                                int authuserId = _db.ForumUser.Single(m => m.UserName.Equals(User.Identity.Name)).UserId;
                                ans.UserId = authuserId;
                                ans.AnsweredTimeDate = DateTime.Now;
                                ans.QuestionId = id.Value;
                                ans.Answer = msg;
                                ans.Rating = 0;
                                _db.Answers.Add(ans);
                                _db.SaveChanges();
                                ViewData["c"] = 4;
                                ViewBag.operation = 1;
                                ViewBag.checkCrontroller = 1;
                                UpdateAns(id.Value);
                                DisplayQuesAnsComments(id.Value);
                            }




                        }
                        else
                        {
                            TempData["AnsId"] = id.Value;
                            DisplayQuesAnsComments(id.Value);
                            ViewBag.operation = 1;
                            ViewBag.checkCrontroller = 1;
                            ViewData["ReqMsg"] = 3;
                            ViewData["Mess"] = "* Answers should not contain less than 10 chracters";

                        }
                    }
                    else
                    {
                        TempData["AnsId"] = id.Value;
                        DisplayQuesAnsComments(id.Value);
                        ViewBag.operation = 1;
                        ViewBag.checkCrontroller = 1;
                        ViewData["ReqMsg"] = 3;
                        ViewData["Mess"] = "*  Empty Field not allowed!.Please Write Your Answer";
                    }


                    UpdateTempQuesId(id.Value);
                    TempData["QiComm"] = id;
                    TempData["AnsId"] = id;

                    DisplayQuesAnsComments(id.Value);
                    ViewBag.operation = 1;
                    ViewBag.checkCrontroller = 1;
                    return View("_PostAnswer");
                }


            }
            else
            {
                if (id == null)
                {

                    ViewData["c"] = 5;
                    UpdateTempQuesId(tempId);
                    DisplayQuesAnsComments(tempId);
                    ViewBag.operation = 1;
                    ViewBag.checkCrontroller = 1;
                }
                ViewData["c"] = 5;
                UpdateTempQuesId(id.Value);
                DisplayQuesAnsComments(id.Value);
                ViewBag.operation = 1;
                ViewBag.checkCrontroller = 1;
                TempData["AreaFQAnsPostController"] = 1;
                return View("_PostAnswer");
            }




            return View("_PostAnswer");

        }