Esempio n. 1
0
 public IEnumerable <Profile> GetChatMembers(Guid id)
 {
     try
     {
         var list     = _chatsRepository.GetChatMembers(id).ToList();
         var profiles = new List <Profile>();
         foreach (var profileId in list)
         {
             var profile = _profilesRepository.GetProfile(profileId);
             profiles.Add(profile);
             if ((DateTime.Now.TimeOfDay - profile.LastQueryDate.TimeOfDay).Minutes < 2 ||
                 !profile.IsOnline.Equals(true))
             {
                 continue;
             }
             _profilesRepository.LogoutProfile(profile.Id);
             profile.IsOnline = false;
         }
         return(profiles);
     }
     catch (SqlException exception)
     {
         var response = new HttpResponseMessage(HttpStatusCode.NotFound)
         {
             Content = new StringContent(exception.Message)
         };
         throw new HttpResponseException(response);
     }
 }
Esempio n. 2
0
 /// <inheritdoc />
 public IEnumerable <Chat> GetProfileChats(Guid id)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         Logger.Debug("Получение пользовательских чатов.");
         try
         {
             connection.Open();
         }
         catch (SqlException exception)
         {
             Logger.Error($"Не могу подключиться к БД, {exception.Message}");
             throw;
         }
         using (var command = connection.CreateCommand())
         {
             command.CommandText =
                 "SELECT chat.* FROM Chats chat JOIN ChatMembers member ON chat.ChatId = member.ChatId " +
                 "WHERE member.ProfileId = @Id";
             command.Parameters.AddWithValue("@Id", id);
             Logger.Info($"Получение чатов пользователя с ИД {id}...");
             using (var reader = command.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     var chatId = reader.GetGuid(reader.GetOrdinal("ChatId"));
                     yield return(new Chat
                     {
                         ChatId = chatId,
                         ChatName = reader.GetString(reader.GetOrdinal("ChatName")),
                         ChatMembers = _chatsRepository.GetChatMembers(chatId)
                     });
                 }
             }
         }
     }
     Logger.Info("Чаты переданы.");
 }