//[ValidateAntiForgeryToken]
 public async Task<ActionResult> QuestionDetails(Guid? PostId)
 {
     var userId = new Guid(User.Identity.GetUserId());
     var QuestionQuery = db.Questions.Where(c => c.QuestionID == PostId) ;
     var postedQuestion = QuestionQuery.FirstOrDefault();
     var selectedSession = postedQuestion.Sessions.Where(c => c.TutorID.Value == userId).FirstOrDefault();
     var selectedStudent = postedQuestion.student;
     var selectedTutor =selectedSession==null? await db.Tutors.FindAsync(userId) : selectedSession.tutor;
     TutorQuestionDetails chatView = new TutorQuestionDetails();
     chatView.session = selectedSession;
     chatView.tutor = selectedTutor;
     chatView.student = selectedStudent;
     chatView.question = postedQuestion;
     chatView.QuestionID = PostId.Value;
     chatView.sessionCount = postedQuestion.Sessions.Count;
 
     return View(chatView);
 }
        public async Task<ActionResult> QuestionsReply(TutorQuestionDetails reply)
        {
            var userId= new Guid(User.Identity.GetUserId());
            var user = db.Tutors.Where(c => c.TutorID == userId).FirstOrDefault();
            var question = db.Questions.Where(c => c.QuestionID == reply.QuestionID);
            var postedQuestion = question.FirstOrDefault();
            var selectedSession = postedQuestion.Sessions.Where(c => c.TutorID.Value == userId).FirstOrDefault();
            if (selectedSession == null)
            { 
                Session obj = new Session();
                obj.SessionID = Guid.NewGuid();
                obj.TutorID = userId;
                //obj.StudentID = reply.StudentID;
                obj.QuestionID = reply.QuestionID;
                obj.PostedTime = DateTime.Now;
                obj.Status = Status.Posted;
                db.sessions.Add(obj);
            
                Reply rep = new Reply();
                rep.ReplyID =  Guid.NewGuid();
                rep.SessionID = obj.SessionID;
                rep.ReplierID = obj.TutorID.Value;
                rep.PostedTime = DateTime.Now;
                reply.replyDetails= reply.replyDetails.Replace(Environment.NewLine, "<br/>");
                rep.Details = reply.replyDetails;
                db.Replies.Add(rep);
                await db.SaveChangesAsync();

                SendNotification(postedQuestion.student.Username, user.Username, user.ProfileImage, "Replied to your question.",true, "Students", "Sessions", "SessionId=" + obj.SessionID);

                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = rep.ReplyID + "$" + rep.SessionID }
                };
            }
            else
            { 
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "null" }
                };
            }
        }
 public async Task<ActionResult> QuestionsReply(TutorQuestionDetails reply)
 {
     var userId= new Guid(User.Identity.GetUserId());
     var question = db.Questions.Where(c => c.QuestionID == reply.QuestionID);
     var postedQuestion = question.FirstOrDefault();
     var selectedSession = postedQuestion.Sessions.Where(c => c.TutorID.Value == userId).FirstOrDefault();
     if (selectedSession == null)
     { 
         Session obj = new Session();
         obj.SessionID = Guid.NewGuid();
         obj.TutorID = userId;
         //obj.StudentID = reply.StudentID;
         obj.QuestionID = reply.QuestionID;
         obj.PostedTime = DateTime.Now;
         obj.Status = Status.Posted;
         db.sessions.Add(obj);
     
         Reply rep = new Reply();
         rep.ReplyID =  Guid.NewGuid();
         rep.SessionID = obj.SessionID;
         rep.ReplierID = obj.TutorID.Value;
         rep.PostedTime = DateTime.Now;
         rep.Details = reply.replyDetails;
         db.Replies.Add(rep);
         await db.SaveChangesAsync();
         return new JsonResult()
         {
             JsonRequestBehavior = JsonRequestBehavior.AllowGet,
             Data = new { result = rep.ReplyID + "$" + rep.SessionID }
         };
     }
     else
     { 
         return new JsonResult()
         {
             JsonRequestBehavior = JsonRequestBehavior.AllowGet,
             Data = new { result = "null" }
         };
     }
 }