Exemplo n.º 1
0
 private int StoreSession(string topic, int startBy)
 {
     try
     {
         ChatSessionViewModel chatsession = new ChatSessionViewModel
         {
             Topic   = topic,
             StartBy = startBy,
             StartOn = System.DateTime.Now
         };
         //var chatManager = (IChatManager)DependencyResolver.Current.GetService(typeof(IChatManager));
         int sessionId = chatManager.AddChatSession(chatsession);
         return(sessionId);
     }
     catch (Exception ex)
     {
         return(-1);
     }
 }
Exemplo n.º 2
0
        private bool JoinSession(int sessionId, int[] userIdlist)
        {
            try
            {
                //userManager = (IUserManager)DependencyResolver.Current.GetService(typeof(IUserManager));
                //var chatManager = (IChatManager)DependencyResolver.Current.GetService(typeof(IChatManager));
                ChatSessionViewModel chatsession = chatManager.GetChatSession(sessionId);
                foreach (int userid in userIdlist)
                {
                    UserViewModel user = userManager.GetViewModel(userid);
                    chatsession.Joinner.Add(user);
                }

                chatManager.JoinSession(chatsession);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        public static ChatSessionDto ToDtoModel(this ChatSessionViewModel model)
        {
            if (model == null)
            {
                return(null);
            }
            ChatSessionDto dto = new ChatSessionDto();

            dto.Id         = model.SessionId;
            dto.Topic      = model.Topic;
            dto.StartBy    = model.StartBy;
            dto.StartOn    = model.StartOn;
            dto.IsFinished = model.IsFinished;
            if (model.Joinner.Count > 0)
            {
                model.Joinner.ForEach(a =>
                {
                    dto.Joinner.Add(a.ToDtoModel());
                });
            }
            return(dto);
        }
Exemplo n.º 4
0
        public static ChatSessionViewModel ToViewModel(this ChatSessionDto chatsessionDto)
        {
            if (chatsessionDto == null)
            {
                return(null);
            }
            ChatSessionViewModel model = new ChatSessionViewModel();

            model.SessionId = chatsessionDto.Id;
            model.Topic     = chatsessionDto.Topic;
            model.Starter   = chatsessionDto.Starter.ToViewModel();
            if (chatsessionDto.Joinner != null)
            {
                chatsessionDto.Joinner.ForEach(j => model.Joinner.Add(j.ToViewModel()));
            }
            if (chatsessionDto.ChatContents != null)
            {
                chatsessionDto.ChatContents.ForEach(c => model.ChatContents.Add(c.ToViewModel()));
            }
            model.StartOn = chatsessionDto.StartOn;
            return(model);
        }