/// <summary> /// Inizializza una chat, se non è già presente. /// </summary> /// <param name="InitUser">L'utente che cerca di aprire la chat.</param> /// <param name="ReceiveUser">L'utente "ricevente"</param> /// <returns>Nel primo caso restituisce la nuova chat, nel secondo quella corretta.</returns> public IMMessagesContainerDTO StarChat(IMUserDTO InitUser, IMUserDTO ReceiveUser) { IMMessagesContainerDTO TempChat = (from ct in Chats where ((ct.UserA.Id == InitUser.Id) && (ct.UserB.Id == ReceiveUser.Id) || (ct.UserA.Id == ReceiveUser.Id) && (ct.UserB.Id == InitUser.Id)) select ct).FirstOrDefault(); if (TempChat != null) { //Restituisco la chat corretta return(TempChat); } else { //Creo la nuova chat TempChat = new Domain.IMMessagesContainerDTO(); TempChat.Id = Guid.NewGuid(); TempChat.UserA = InitUser; TempChat.UserB = ReceiveUser; TempChat.UserA.LastAccess = DateTime.Now; TempChat.UserB.LastAccess = DateTime.Now; TempChat.UserA.IsActive = true; TempChat.UserB.IsActive = false; TempChat.UserA.IsEnter = true; TempChat.UserB.IsEnter = false; //TempChat.Person1.IsChatvisible = true; //TempChat.Person2.IsChatvisible = true; TempChat.IsStarted = false; //Original: TempChat.UserDiscarded = ReceiveUser.Id; TempChat.UserDiscarded = ReceiveUser.PersonId; TempChat.Messages = new List <IMMessageDTO>(); Chats.Add(TempChat); return(TempChat); // this.Messages = new List<Ct1o1_Message_DTO>(); } }
public IMMessagesContainerDTO CreateChat(IMUserDTO StartUser, IMUserDTO TargetUser) { return(oChatManager.StarChat(StartUser, TargetUser)); }