private int IsExistChat(ChatDTO chatDTO) { var chat = repositories.ChatRepos.Get().Where(ch => ch.UniqueName == chatDTO.UniqueName).FirstOrDefault(); if (chat == null) { return(-1); } else { return(chat.Id); } }
public ChatDTO CreateNewChat(ChatDTO newChatDTO) { var id = IsExistChat(newChatDTO); if (id == -1) { repositories.ChatRepos.Insert(mapper.Map <Chat>(newChatDTO)); repositories.Save(); return(mapper.Map <ChatDTO>(repositories.ChatRepos.Get().LastOrDefault())); } else { return(null); } }
public IEnumerable <MessageDTO> GetMessagesByChat(ChatDTO chat) { var res_chat = unit.ChatRepository.Get(c => c.Id == chat.Id, includeProperties: nameof(Chat.Messages))?.FirstOrDefault(); return(_mapper.Map <IEnumerable <Message>, IEnumerable <MessageDTO> >(res_chat.Messages)); }
public IEnumerable <UserDTO> GetUsersByChat(ChatDTO chat) { return(_mapper.Map <IEnumerable <User>, IEnumerable <UserDTO> >((unit.ChatRepository.GetById(chat.Id).Users))); }