public void ConnectDoctor(string email) { var id = Context.ConnectionId; var doctor = _db.Doctors.Where(x=>x.Email.Equals(email)).FirstOrDefault(); var doctorDetail = Doctors.Where(x => x.Email.Equals(email)).FirstOrDefault(); helper.UpdateDoctorsStatus(email, Doctors, ConnectedUsers); //Add User UserDetail userDetail = new UserDetail { ConnectionId = id, // CountMessageUnRead = business.CountMessageUnRead(doctor), ProfilePicture = doctor.ProfilePicture, FullName = doctor.FullName, Email = doctor.Email, OnlineStatus = OnlineStatus.Online }; //Show List of Lastest contact var userDetailList = helper.GetLastestConversationList(email, ConnectedUsers); userDetail.ConversationList = userDetailList; ConnectedUsers.Add(userDetail); Debug.WriteLine("Size of userDetailList: " + userDetailList.Count); Clients.Caller.onGetConversationList(userDetailList); Clients.AllExcept(id).onRefreshDoctorList(); }
public void addUserDetail(UserDetail userDetail) { users.Add(userDetail); }
public void addUserDetail(UserDetail userDetail ) { users.Add(userDetail); }
public void ConnectDoctor(string username) { business = new ConversationBusiness(_db); var id = Context.ConnectionId; var doctor = _db.Doctors.Where(x=>x.Username.Equals(username)).FirstOrDefault(); var doctorDetail = Doctors.Where(x => x.Username.Equals(username)).FirstOrDefault(); //Update Doctor list status if (doctorDetail == null) { doctorDetail = new DoctorDetail { ConnectionId = id, CountMessageUnRead = business.CountMessageUnRead(doctor), ProfilePicture = doctor.ProfilePicture, IsOnline = doctor.IsOnline, FullName = doctor.FullName, Username = doctor.Username, SpeciatyField = doctor.SpecialtyField.Name }; Doctors.Add(doctorDetail); } else { doctorDetail.CountMessageUnRead = business.CountMessageUnRead(doctor); doctorDetail.IsOnline = doctor.IsOnline; } //Add User UserDetail userDetail = new UserDetail { ConnectionId = id, CountMessageUnRead = business.CountMessageUnRead(doctor), ProfilePicture = doctor.ProfilePicture, FullName = doctor.FullName, Username = doctor.Username, }; //Show List of Lastest contact var userDetailList = new List<UserDetail>(); var conversations = _db.Conversations.Where( x => x.DoctorId == doctor.UserId). OrderByDescending(x=>x.LatestTimeFromPatient ).ToList(); foreach (var conversation in conversations) { var existUser = userDetailList.Where (x => x.Username == conversation.Patient.Username).FirstOrDefault(); if (existUser == null) { //Check user online or not var connectedUser = ConnectedUsers.Where (x => x.Username == conversation.Patient.Username).FirstOrDefault(); var IsOnline = (connectedUser != null && connectedUser.IsOnline) ? true: false; UserDetail userDetailCon = new UserDetail { FullName = conversation.Patient.FullName, LastestContent = conversation.LatestContentFromPatient, LastestTime = conversation.LatestTimeFromPatient, ProfilePicture = conversation.Patient.ProfilePicture, Username = conversation.Patient.Username, IsRead = conversation.IsRead, IsOnline = IsOnline }; userDetailList.Add(userDetailCon); } } ConnectedUsers.Add(userDetail); Debug.WriteLine("Size of userDetailList: " + userDetailList.Count); // send to all except caller client Clients.Caller.onGetConversationList(userDetailList); Clients.AllExcept(id).onGetDoctorList(Doctors); }
public void GetMessageList(string username) { business = new ConversationBusiness(_db); var id = Context.ConnectionId; var fromUserDetail = ConnectedUsers.Where(x => x.ConnectionId == id).FirstOrDefault(); var fromUser = _db.Users.Where(x => x.Username.Equals(fromUserDetail.Username)).FirstOrDefault(); var toUser = _db.Users.Where(x => x.Username.Equals(username)).FirstOrDefault(); var toUserDetail = ConnectedUsers.Where(x => x.Username.Equals(username)).FirstOrDefault(); //Check if toUserDetail is not online yet if (toUserDetail == null) { toUserDetail = new UserDetail { FullName = toUser.FullName, Username = toUser.Username, IsOnline = false, ProfilePicture = toUser.ProfilePicture }; } var doctor = _db.Doctors.Where(u => u.Username.Equals(fromUser.Username)).FirstOrDefault(); var patient = new Patient(); if (doctor == null) { doctor = _db.Doctors.Where(u => u.Username.Equals(toUser.Username)).FirstOrDefault(); patient = _db.Patients.Where(u => u.Username.Equals(fromUser.Username)).FirstOrDefault(); } else { patient = _db.Patients.Where(u => u.Username.Equals(toUser.Username)).FirstOrDefault(); } if (doctor != null && patient != null) { Debug.WriteLine("Patient: " + patient.Username + " " + "Doctor: " + doctor.Username); DoctorDetail doctorDetail = Doctors.Where(u => u.Username.Equals(doctor.Username)).FirstOrDefault(); var newestConversation = _db.Conversations.Where( con => (con.PatientId == patient.UserId) && (con.DoctorId == doctor.UserId)) .OrderByDescending(con => con.DateConsulted).FirstOrDefault(); if (newestConversation != null) { var conversationDetails = _db.ConversationDetails.Where(cd => cd.Conversation.ConversationId == newestConversation.ConversationId). OrderBy(cd => cd.CreatedDate).ToList(); //Convert conversationDetails to MessageDetails var messageDetails = new List<MessageDetail>(); foreach (var conversationDetail in conversationDetails) { String date = (DateTime.Now.Subtract(conversationDetail.CreatedDate).Days) > 1 ? String.Format("{0:HH:mm:ss}", conversationDetail.CreatedDate) : String.Format("{0:dd/mm/yyyy HH:mm:ss}", conversationDetail.CreatedDate); MessageDetail messageDetail = new MessageDetail { Content = conversationDetail.Content, CreatedDate = date, Username = conversationDetail.User.Username, IsRead = conversationDetail.IsRead }; messageDetails.Add(messageDetail); } Debug.WriteLine(messageDetails.Count); if (fromUserDetail.Username.Equals(doctor.Username)) { business.MarkConversationAsRead(newestConversation); this.ConnectDoctor(doctor.Username); } Clients.Caller.onGetMessageList(fromUserDetail, toUserDetail, messageDetails); } else { Clients.Caller.onGetMessageList(fromUserDetail, toUserDetail, ""); } } }
public void ConnectPatient(string email) { var id = Context.ConnectionId; var userDetail = ConnectedUsers.Where(x => x.Email.Equals(email)).FirstOrDefault(); if (userDetail == null) { var user = _db.Users.Where(x => x.Email.Equals(email)).FirstOrDefault(); userDetail = new UserDetail { ConnectionId = id, CountMessageUnRead = business.CountMessageUnRead(user), Email = email, FullName = user.FullName, ProfilePicture = user.ProfilePicture, OnlineStatus = OnlineStatus.Online }; ConnectedUsers.Add(userDetail); userDetail.DoctorList = helper.GetListDoctorConversation(email, ConnectedUsers); } Clients.Caller.onGetDoctorList(userDetail.DoctorList); Clients.Caller.onMessageUnRead(userDetail); //Update status for others var doctorList = ConnectedUsers.Where(x=>x.ConversationList != null).ToList(); foreach (UserDetail doctor in doctorList) { var patient = doctor.ConversationList.Find(x => x.Email == userDetail.Email); if (patient != null) { patient.OnlineStatus = OnlineStatus.Online; } Clients.Client(doctor.ConnectionId).onGetConversationList(doctor.ConversationList); } }