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" } }; } }
public async Task<JsonResult> PostQuestion([Bind(Include = "QuestionID,StudentID,TutorID,Title,Details,Status,Amount,CategoryID,DueDate,PostedTime")] QuestionViewModel question) { if (ModelState.IsValid) { Question quest = Mapper.Map<QuestionViewModel, Question>(question); quest.QuestionID = Guid.NewGuid(); quest.PostedTime = DateTime.Now; //initial posted Question Status quest.Status = Status.Posted; quest.TutorID = question.TutorID; if(question.TutorID!=null) { Session obj = new Session(); obj.SessionID = Guid.NewGuid(); obj.TutorID = question.TutorID; obj.QuestionID = quest.QuestionID; obj.PostedTime = DateTime.Now; obj.Status = Status.Posted; obj.NewMessageTutor = true; db.sessions.Add(obj); Reply rep = new Reply(); rep.ReplyID = Guid.NewGuid(); rep.SessionID = obj.SessionID; rep.ReplierID = quest.StudentID; rep.PostedTime = DateTime.Now; rep.Details =quest.Title; db.Replies.Add(rep); } //user posting question id quest.StudentID = new Guid(User.Identity.GetUserId()); db.Questions.Add(quest); await db.SaveChangesAsync(); var student=db.Students.Find(quest.StudentID); string response = quest.QuestionID +"$"+quest.Title+ "$" + student.ProfileImage + "%" + User.Identity.Name + "$" + quest.Amount+"$"+quest.PostedTime+"$" + quest.DueDate ; return new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { result = response } }; } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName"); return null; }
public async Task<JsonResult> PostQuestion([Bind(Include = "QuestionID,StudentID,TutorID,Title,Details,Status,Amount,CategoryID,DueDate,PostedTime")] QuestionViewModel question) { if (ModelState.IsValid) { Question quest = Mapper.Map<QuestionViewModel, Question>(question); quest.QuestionID = Guid.NewGuid(); quest.PostedTime = DateTime.Now; //initial posted Question Status quest.Status = Status.Posted; quest.TutorID = question.TutorID; quest.Details=quest.Details.Replace(Environment.NewLine, "<br/>"); bool singleTutor = false; string sessionId = null; string postId = quest.QuestionID.ToString(); if(question.TutorID!=null) { singleTutor = true; Session obj = new Session(); obj.SessionID = Guid.NewGuid(); sessionId = obj.SessionID.ToString(); obj.TutorID = question.TutorID; obj.QuestionID = quest.QuestionID; obj.PostedTime = DateTime.Now; obj.Status = Status.Posted; obj.NewMessageTutor = true; db.sessions.Add(obj); Reply rep = new Reply(); rep.ReplyID = Guid.NewGuid(); rep.SessionID = obj.SessionID; rep.ReplierID = quest.StudentID; rep.PostedTime = DateTime.Now; rep.Details =quest.Title; db.Replies.Add(rep); } //user posting question id quest.StudentID = new Guid(User.Identity.GetUserId()); db.Questions.Add(quest); await db.SaveChangesAsync(); var student=db.Students.Find(quest.StudentID); string response = quest.QuestionID +"$"+quest.Title+ "$" + student.ProfileImage + "%" + User.Identity.Name + "$" + quest.Amount+"$"+quest.PostedTime+"$" + quest.DueDate ; //send emails if (singleTutor == false) { var tutors = db.Tutors.Where(c => c.IsCompletedProfile == true).ToList(); var allusers = db.Users.ToList(); foreach (var v in tutors) { var emailUser = allusers.Where(c => c.UserName == v.Username).FirstOrDefault(); SendNotification(emailUser.UserName, student.Username, student.ProfileImage, "New Question posted.",true, "Tutors", "QuestionDetails", "PostId=" + postId); if (emailUser != null) { // Send the emails here var email = emailUser.Email; String subject = "New Question Posted on MezoExperts.com"; String bodyText = question.Title; String optional = quest.Details; string FileTemplate = "email.html"; await sendEmail(email, subject, bodyText, FileTemplate, optional); } } } else { var tutor = db.Users.Find(quest.TutorID.ToString()); SendNotification(tutor.UserName, student.Username, student.ProfileImage, "I have a new task for you.",true, "Tutors", "Sessions", "SessionId=" + sessionId); var email = tutor.Email; String subject = "New Question Posted on MezoExperts.com"; String bodyText = question.Title; String optional = quest.Details; string FileTemplate = "email.html"; await sendEmail(email, subject, bodyText, FileTemplate, optional); } return new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { result = response } }; } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName"); return null; }