public ActionResult PostAnswer(UsersAnsPost post, int id, string answer)
        {
            DisplayAnsList(id);

            if (ModelState.IsValid)
            {
                var ans = new Answers();
                var authuserId = _db.ForumUser.Single(m => m.UserName.Equals(User.Identity.Name)).UserId;
                ans.UserId = authuserId;
                ans.AnsweredTimeDate = DateTime.Now;
                ans.QuestionId = id;
                ans.Answer = answer;
                _db.Answers.Add(ans);
                _db.SaveChanges();
                DisplayAnsList(id);

            }

            return View();
        }
        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");





        }
        public ActionResult PostAnswer(int? id, string msg)
        {


            if (Request.IsAuthenticated)
            {
                if (id == null)
                {
                    int tempId = _db.Temp.Single(m => m.Id.Equals(1)).TempId.Value;

                    if (msg != "")
                    {
                        if (msg.Length >= 10)
                        {
                            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;


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

                            ViewData["PostedAnsAndUserInformation"] = (from a in _db.Answers
                                                                       join u in _db.ForumUser on a.UserId equals u.UserId
                                                                       where a.QuestionId.Equals(tempId)
                                                                       select new AnsPostedUser() { Username = u.UserName, Image = u.Image, PostedDate = a.AnsweredTimeDate, Answer = a.Answer }).ToList();





                            ViewData["GetQuestionAndImageByID"] = (from q in _db.Questions
                                                                   join u in _db.ForumUser on q.UserId equals u.UserId
                                                                   where q.QuestionId.Equals(tempId)
                                                                   select new AnsPostedUser() { Image = u.Image, Question = q.Question });


                        }
                        else
                        {
                            ViewData["GetQuestionAndImageByID"] = (from q in _db.Questions
                                                                   join u in _db.ForumUser on q.UserId equals u.UserId
                                                                   where q.QuestionId.Equals(tempId)
                                                                   select new AnsPostedUser() { Image = u.Image, Question = q.Question });

                            ViewData["ReqMsg"] = 3;
                            ViewData["Mess"] = "* Answers should not contain less than 10 chracters";
                            return View();
                        }
                    }
                    else
                    {

                        ViewData["GetQuestionAndImageByID"] = (from q in _db.Questions
                                                               join u in _db.ForumUser on q.UserId equals u.UserId
                                                               where q.QuestionId.Equals(tempId)
                                                               select new AnsPostedUser() { Image = u.Image, Question = q.Question });


                        ViewData["ReqMsg"] = 3;
                        ViewData["Mess"] = "*  Empty Field not allowed!.Please Write Your Answer";
                        return View();
                    }
                }
                else
                {
                    if (msg != "")
                    {
                        if (msg.Length >= 10)
                        {


                            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;

                            ViewData["Date"] = ans.AnsweredTimeDate;
                            _db.Answers.Add(ans);
                            _db.SaveChanges();
                            UpdateAns(id.Value);
                            ViewData["PostedAnsAndUserInformation"] = (from a in _db.Answers
                                                                       join u in _db.ForumUser on a.UserId equals u.UserId
                                                                       where a.QuestionId.Equals(id.Value)
                                                                       select new AnsPostedUser() { Username = u.UserName, Image = u.Image, PostedDate = a.AnsweredTimeDate, Answer = a.Answer }).ToList();

                            ViewData["GetQuestionAndImageByID"] = (from q in _db.Questions
                                                                   join u in _db.ForumUser on q.UserId equals u.UserId
                                                                   where q.QuestionId.Equals(id.Value)
                                                                   select new AnsPostedUser() { Image = u.Image, Question = q.Question });

                            //return View();
                        }
                        else
                        {
                            ViewData["GetQuestionAndImageByID"] = (from q in _db.Questions
                                                                   join u in _db.ForumUser on q.UserId equals u.UserId
                                                                   where q.QuestionId.Equals(id.Value)
                                                                   select new AnsPostedUser() { Image = u.Image, Question = q.Question });

                            ViewData["ReqMsg"] = 3;
                            ViewData["Mess"] = "* Answers should not contain less than 10 chracters";

                        }
                    }
                    else
                    {
                        ViewData["GetQuestionAndImageByID"] = (from q in _db.Questions
                                                               join u in _db.ForumUser on q.UserId equals u.UserId
                                                               where q.QuestionId.Equals(id.Value)
                                                               select new AnsPostedUser() { Image = u.Image, Question = q.Question });

                        ViewData["ReqMsg"] = 3;
                        ViewData["Mess"] = "*  Empty Field not allowed!.Please Write Your Answer";


                    }
                }

            }
            else
            {

                ViewData["GetQuestionAndImageByID"] = (from q in _db.Questions
                                                       join u in _db.ForumUser on q.UserId equals u.UserId
                                                       where q.QuestionId.Equals(id.Value)
                                                       select new AnsPostedUser() { Image = u.Image, Question = q.Question });

                TempData["FQACPostAnsUnAnsweredQuestion"] = 1;
                ViewData["c"] = 3;
                return View();
            }
            ViewData["GetQuestionAndImageByID"] = (from q in _db.Questions
                                                   join u in _db.ForumUser on q.UserId equals u.UserId
                                                   where q.QuestionId.Equals(id.Value)
                                                   select new AnsPostedUser() { Image = u.Image, Question = q.Question }).ToList();

            return View();
        }
        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");

        }