public async Task<ActionResult>Sessions(Guid SessionId) { var session=await db.sessions.FindAsync(SessionId); if (session.question.student.Username == User.Identity.Name) { ChatModel obj = new ChatModel(); obj.session = session; obj.status = db.online.Where(c => c.Username == session.tutor.Username).FirstOrDefault().Status; obj.session.Replies = obj.session.Replies.OrderBy(c => c.PostedTime).ToList(); if (!string.IsNullOrEmpty(session.question.student.Timezone)) { string[] splited = session.question.student.Timezone.Split('$'); string[] hoursMin = splited[1].Split(':'); double minutes = (Convert.ToDouble(hoursMin[0]) * 60); if (minutes < 0) minutes = minutes - Convert.ToDouble(hoursMin[1]); else minutes = minutes + Convert.ToDouble(hoursMin[1]); obj.offsetTime = minutes; } return View(obj); } else { return RedirectToAction("Unauthorized", "Home", ""); } }
public async Task<ActionResult>Sessions(Guid SessionId) { var session=await db.sessions.FindAsync(SessionId); ChatModel obj = new ChatModel(); obj.session = session; obj.session.Replies=obj.session.Replies.OrderBy(c => c.PostedTime).ToList(); return View(obj); }
public async Task<ActionResult> Chat(ChatModel reply) { Reply obj = new Reply(); obj.ReplyID = Guid.NewGuid(); obj.ReplierID = new Guid(User.Identity.GetUserId()); obj.SessionID = reply.sessionID; obj.PostedTime = DateTime.Now; reply.replyDetail=reply.replyDetail.Replace(Environment.NewLine, "<br/>"); obj.Details = reply.replyDetail; db.Replies.Add(obj); var session = db.sessions.Where(c => c.SessionID == obj.SessionID).FirstOrDefault(); session.NewMessageStudent = true; db.Entry(session).State = EntityState.Modified; await db.SaveChangesAsync(); string adjustedTimeTutor; string adjustedTimeStudent; DateTime TutorTime = obj.PostedTime.AddHours(7); DateTime StudentTime = obj.PostedTime.AddHours(7); if (!string.IsNullOrEmpty(session.tutor.Timezone)) { string[] splited = session.tutor.Timezone.Split('$'); string[] hoursMin = splited[1].Split(':'); double minutes = (Convert.ToDouble(hoursMin[0]) * 60); if (minutes < 0) minutes = minutes - Convert.ToDouble(hoursMin[1]); else minutes = minutes + Convert.ToDouble(hoursMin[1]); TutorTime=TutorTime.AddMinutes(minutes); } adjustedTimeTutor = TutorTime.ToString(); if (!string.IsNullOrEmpty(session.question.student.Timezone)) { string[] splited = session.question.student.Timezone.Split('$'); string[] hoursMin = splited[1].Split(':'); double minutes = (Convert.ToDouble(hoursMin[0]) * 60); if (minutes < 0) minutes = minutes - Convert.ToDouble(hoursMin[1]); else minutes = minutes + Convert.ToDouble(hoursMin[1]); StudentTime= StudentTime.AddMinutes(minutes); } adjustedTimeStudent = StudentTime.ToString(); var context = GlobalHost.ConnectionManager.GetHubContext<TutorStudentChat>(); var username = User.Identity.Name; //part moved up var student = db.sessions.Where(c => c.SessionID == obj.SessionID).FirstOrDefault().question.student; var username2 = student.Username; var status = db.online.Where(c => c.Username == username2).FirstOrDefault().Status; var imgsrc = db.Tutors.Where(c => c.Username == username).FirstOrDefault().ProfileImage; string message = generateMessage(username, obj.Details, imgsrc, adjustedTimeTutor, obj.ReplyID.ToString(), status); SendChatTutorReciever(obj.SessionID.ToString(),username, message, context); //send message to urself string message2 = generateMessage(username, obj.Details, imgsrc, adjustedTimeStudent, obj.ReplyID.ToString(), status); SendChatStudentReiever(obj.SessionID.ToString(), username2, message2, context); //send message to other person //context.Clients.All.test("hello world"); return new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { result = obj.ReplyID + "$" + obj.SessionID } }; }
public async Task<ActionResult> Sessions(Guid SessionId) { var session = await db.sessions.FindAsync(SessionId); ChatModel obj = new ChatModel(); obj.session = session; var result = db.online.Where(c => c.Username == session.question.student.Username).FirstOrDefault(); if (result != null) obj.status = result.Status; else obj.status = false; var result2 = db.online.Where(c => c.Username == session.tutor.Username).FirstOrDefault(); if (result2 != null) obj.status2nd = result2.Status; else obj.status2nd = false; obj.session.Replies = obj.session.Replies.OrderBy(c => c.PostedTime).ToList(); obj.offer.amount = obj.session.OfferedFees; return View("Question/Sessions", obj); }
public async Task<ActionResult> Chat(ChatModel reply) { Reply obj = new Reply(); obj.ReplyID = Guid.NewGuid(); obj.ReplierID= new Guid(User.Identity.GetUserId()); obj.SessionID = reply.sessionID; obj.PostedTime = DateTime.Now; obj.Details = reply.replyDetail; db.Replies.Add(obj); var session = db.sessions.Where(c => c.SessionID == obj.SessionID).FirstOrDefault(); session.NewMessageTutor = true; db.Entry(session).State = EntityState.Modified; await db.SaveChangesAsync(); var context = GlobalHost.ConnectionManager.GetHubContext<TutorStudentChat>(); var username = User.Identity.Name; var imgsrc = db.Students.Where(c => c.Username == username).FirstOrDefault().ProfileImage; string message = generateMessage(username, obj.Details, imgsrc, obj.PostedTime.ToString(),obj.ReplyID.ToString()); SendChatMessageStudentReciever(obj.SessionID.ToString(), username, message, context); //send message to urself var tutor = db.sessions.Where(c => c.SessionID == obj.SessionID).FirstOrDefault().tutor; var username2 = tutor.Username; SendChatMessageTutorReciever(obj.SessionID.ToString(), username2, message, context); //send message to other person return new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { result = obj.ReplyID +"$" + obj.SessionID } }; }