public ActionResult Index() { UserInfoBO user = (UserInfoBO)SessionManager.GetUserInfo(); ChatIndexViewModel model = new ChatIndexViewModel(); CHAT_NOIDUNGBusiness = Get <CHAT_NOIDUNGBusiness>(); model.ListChat = CHAT_NOIDUNGBusiness.GetListChatHistory(user.DeptParentID.Value, user.ID, user.TENDANGNHAP, user.HOTEN); return(View(model)); }
public ChatController(PulseContext pulseContext, UserManager <Account> userManager) { _pulseContext = pulseContext; _userManager = userManager; _model = new ChatViewModel(); _coachIndex = new ChatIndexViewModel(); _adminIndex = new ChatAdminViewModel(); _resourcesController = new ResourcesController(); }
public ActionResult Index() { if (User.Identity.IsAuthenticated) { IChatData chatData = new StaticChatData(); var viewModel = new ChatIndexViewModel(this.User.Identity.Name, chatData.ChatMessages); return(View(viewModel)); } return(View((ChatIndexViewModel)null)); }
// GET: Chat public ActionResult Index() { ChatIndexViewModel viewModel = new ChatIndexViewModel(); PersonaModel utente = Session["utente"] as PersonaModel; // riepilogo chat, con ultima chat per utente in evidenza using (DatabaseContext db = new DatabaseContext()) { db.Database.Connection.Open(); var a = db.CHAT .Where(m => m.STATO != (int)StatoChat.ELIMINATO && m.ID_MITTENTE == utente.Persona.ID) .AsEnumerable() .Select(m => new ChatViewModel() { Id = m.ID , MittenteId = m.ID_MITTENTE , Mittente = new PersonaModel(m.PERSONA) , DestinatarioId = m.ID_DESTINATARIO , Destinatario = new PersonaModel(m.PERSONA1) , DestinatarioIdAttivita = m.ID_DESTINATARIO_ATTIVITA , DestinatarioAttivita = new AttivitaModel(m.ATTIVITA1) , Testo = m.TESTO , DataInserimento = m.DATA_INSERIMENTO , DataModifica = m.DATA_MODIFICA , Stato = (StatoChat)m.STATO }); var b = db.CHAT .Where(m => m.STATO == (int)Stato.ATTIVO && m.ID_DESTINATARIO == utente.Persona.ID) .AsEnumerable() .Select(m => new ChatViewModel() { Id = m.ID , MittenteId = m.ID_DESTINATARIO , Mittente = new PersonaModel(m.PERSONA1) , DestinatarioId = m.ID_MITTENTE , Destinatario = new PersonaModel(m.PERSONA) , DestinatarioIdAttivita = m.ID_MITTENTE_ATTIVITA , DestinatarioAttivita = new AttivitaModel(m.ATTIVITA) , Testo = m.TESTO , DataInserimento = m.DATA_INSERIMENTO , DataModifica = m.DATA_MODIFICA , Stato = (StatoChat)m.STATO }); var lista = a.Concat(b) .OrderByDescending(m => m.DataModifica) .OrderByDescending(m => m.DataInserimento) .GroupBy(m => new { m.MittenteId, m.DestinatarioId }) .Select(m => m.FirstOrDefault()) .ToList(); for (int i = 0; i < lista.Count; i++) { ChatViewModel chat = lista[i]; chat.Mittente.Foto = chat.Mittente.Persona.PERSONA_FOTO.OrderByDescending(m => m.ORDINE).AsEnumerable() .Select(m => new FotoModel(m.ALLEGATO)).ToList(); if (chat.DestinatarioId != null) { chat.Destinatario.Foto = chat.Destinatario.Persona.PERSONA_FOTO.OrderByDescending(m => m.ORDINE).AsEnumerable() .Select(m => new FotoModel(m.ALLEGATO)).ToList(); } if (chat.DestinatarioIdAttivita != null) { chat.DestinatarioAttivita.Foto = chat.DestinatarioAttivita.Attivita.ATTIVITA_FOTO.OrderByDescending(m => m.ORDINE).AsEnumerable() .Select(m => new FotoModel(m.ALLEGATO)).ToList(); } UtenteProfiloViewModel soggettoChat = null; if (chat.MittenteId == utente.Persona.ID) { if (chat.DestinatarioIdAttivita != null) { soggettoChat = new UtenteProfiloViewModel(chat.DestinatarioAttivita); } else { soggettoChat = new UtenteProfiloViewModel(chat.Destinatario); } } else { if (chat.MittenteIdAttivita != null) { soggettoChat = new UtenteProfiloViewModel(chat.MittenteAttivita); } else { soggettoChat = new UtenteProfiloViewModel(chat.Mittente); } } if (i == 0) { viewModel.UltimaChat = chat; viewModel.listaChat = new List <UtenteProfiloViewModel>(); } viewModel.listaChat.Add(soggettoChat); } RefreshPunteggioUtente(db); } return(View(viewModel)); }