Esempio n. 1
0
        public async Task <ListResultDto <ChatSessionDto> > GetUserSessions(GetUserSessionsInput input)
        {
            var list = await _chatSessionMemberRepository.GetAllIncluding(member => member.ChatSession)
                       .Where(member => member.UserId == input.User.UserId)
                       .Select(member => member.ChatSession)
                       .ToListAsync(_httpContextAccessor.HttpContext.RequestAborted);

            var dtos = list.Select(item =>
            {
                ChatSessionDto chatSessionDto = ObjectMapper.Map <ChatSessionDto>(item);
                if (chatSessionDto.SessionType == ChatSessionType.Private)
                {
                    var rs = GetUserByPrivateSessionName(item.Name);

                    if (rs != null)
                    {
                        if (rs.Item1.TenantId != input.User.TenantId && rs.Item1.UserId != input.User.UserId)
                        {
                            chatSessionDto.SourceTenantId = rs.Item1.TenantId;
                            chatSessionDto.Name           = _userRepository.GetAll().Where(u => u.Id == rs.Item1.UserId).Select(u => u.Name).SingleOrDefault();
                        }

                        if (rs.Item2.TenantId != input.User.TenantId && rs.Item2.UserId != input.User.UserId)
                        {
                            chatSessionDto.SourceTenantId = rs.Item2.TenantId;
                            chatSessionDto.Name           = _userRepository.GetAll().Where(u => u.Id == rs.Item2.UserId).Select(u => u.Name).SingleOrDefault();
                        }
                    }
                }
                return(chatSessionDto);
            }).ToList();

            return(new ListResultDto <ChatSessionDto>(dtos));
        }
Esempio n. 2
0
        public int CreateChatSession(ChatSessionDto chatsession)
        {
            ChatSession entity = chatSessionDtoMapper.Map(chatsession);

            chatSessionRepository.Add(entity);
            return(entity.Id);
        }
Esempio n. 3
0
        public ChatSessionDto EndChatSession(ChatSessionDto chatsession)
        {
            ChatSession entity = chatSessionDtoMapper.Map(chatsession);

            chatSessionRepository.Update(entity, null);
            return(chatsession);
        }
 public void JoinToSession([FromBody] ChatSessionDto dto)
 {
     if (dto == null)
     {
         throw new ArgumentNullException("ChatSessionDto");
     }
     var dto2 = chatSessionBO.JoinChatSession(dto);
 }
        public int CreateChatSession([FromUri] ChatSessionDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException("request");
            }

            return(chatSessionBO.CreateChatSession(dto));
        }
Esempio n. 6
0
        public ChatSessionDto JoinChatSession(ChatSessionDto chatsession)
        {
            ChatSession entity = chatSessionDtoMapper.Map(chatsession);

            foreach (var joinner in entity.ChatSessionJoinners)
            {
                chatSessionJoinnerRepository.Add(joinner);
            }

            return(chatsession);
        }
 public ChatSessionDto JoinSession([FromBody] ChatSessionDto dto)
 {
     if (ModelState.IsValid)
     {
         return(chatSessionBO.EndChatSession(dto));
     }
     else
     {
         string message = ModelState.ToErrorMessage();
         throw new Exception(message);
     }
 }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }