Exemple #1
0
 public IEnumerable <Attach> GetMessageAttachs(Guid messageid)
 {
     if (!MessageExists(messageid))
     {
         var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
         {
             Content      = new StringContent($"Сообщение с ID = {messageid} не найденпо"),
             ReasonPhrase = "Message ID Not Found"
         };
         throw new HttpResponseException(resp);
     }
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         using (var command = connection.CreateCommand())
         {
             command.CommandText = "SELECT AttachId FROM Attachs WHERE MessageId = @id";
             command.Parameters.AddWithValue("@id", messageid);
             using (var reader = command.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     yield return(_attachsRepository.Get(reader.GetGuid(reader.GetOrdinal("AttachId"))));
                 }
             }
         }
     }
 }
Exemple #2
0
 public IEnumerable <Attach> GetChatAttachs(Guid id)
 {
     if (!ChatExists(id))
     {
         var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
         {
             Content      = new StringContent($"Чат с ID = {id} не найден"),
             ReasonPhrase = "Chat ID Not Found"
         };
         throw new HttpResponseException(resp);
     }
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         using (var command = connection.CreateCommand())
         {
             command.CommandText = "SELECT AttachId FROM Attachs a INNER JOIN Messages m ON " +
                                   "a.MessageId = m.MessageId WHERE m.ChatId = @id";
             command.Parameters.AddWithValue("@id", id);
             using (var reader = command.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     yield return(_attachsRepository.Get(reader.GetGuid(reader.GetOrdinal("AttachId"))));
                 }
             }
         }
     }
 }