Example #1
0
        public static Chat CreateChat(int UserOneID, int UserTwoID)
        {
            chat chat = new chat();
            using (var context = new HotSaleDBEntities())
            {

                chat.user1 = context.users.ToList().SingleOrDefault(x => x.ID == UserOneID);
                chat.user2 = context.users.ToList().SingleOrDefault(x => x.ID == UserTwoID);
                context.chats.Add(chat);
                context.SaveChanges();
                context.users.ToList().SingleOrDefault(x => x.ID == UserOneID).chats.Add(chat);
                context.users.ToList().SingleOrDefault(x => x.ID == UserTwoID).chats.Add(chat);
                context.SaveChanges();

            }
            Chat Chat = new Chat();
            Chat.ID = chat.ID;
            Chat.UserFirst = new User();
            Chat.UserFirst.ID = chat.user1.ID;
            Chat.UserFirst.Name = chat.user1.Name;
            Chat.UserFirst.Surname = chat.user1.Surname;
            Chat.UserFirst.Avatar = chat.user1.Avatar;
            Chat.UserSecond = new User();
            Chat.UserSecond.ID = chat.user2.ID;
            Chat.UserSecond.Name = chat.user2.Name;
            Chat.UserSecond.Surname = chat.user2.Surname;
            Chat.UserSecond.Avatar = chat.user2.Avatar;
            Chat.Messages = new List<Messages>();

            return Chat;
        }
Example #2
0
 public void OnChatCreated(Chat chat,int UsrId)
 {
     if (_connections.IfExists(UsrId))
     {
         Clients.Client(_connections.GetConnection(UsrId)).NewChatCreated(chat);
      }
 }
Example #3
0
 public static IList<Chat> GetChats(List<int> ChatIDs)
 {
     IList<Chat> Chats = new List<Chat>();
     using (var context = new HotSaleDBEntities())
     {
         context.chats.ToList().ForEach(chat =>
     {
         ChatIDs.ForEach(id =>
         {
             if(chat.ID == id)
             {
                 Chat Chat = new Chat();
                 Chat.ID = id;
                 Chat.UserFirst = new User();
                 Chat.UserFirst.ID = chat.user1.ID;
                 Chat.UserFirst.Name = chat.user1.Name;
                 Chat.UserFirst.Surname = chat.user1.Surname;
                 Chat.UserFirst.Avatar = chat.user1.Avatar;
                 Chat.UserSecond = new User();
                 Chat.UserSecond.ID = chat.user2.ID;
                 Chat.UserSecond.Name = chat.user2.Name;
                 Chat.UserSecond.Surname = chat.user2.Surname;
                 Chat.UserSecond.Avatar = chat.user2.Avatar;
                 chat.messages.ToList().ForEach(mssg => { Messages Mssg = new Messages();
                                                 Mssg.ID = mssg.ID;
                                                 Mssg.Message = mssg.Message1;
                                                 Mssg.Sender = mssg.Sender;
                                                 Chat.Messages.Add(Mssg);
                                                 });
                 Chats.Add(Chat);
             }
         });
     });
     }
     return Chats;
 }