Exemple #1
0
        public IHttpActionResult PostReadMessages([FromBody] CReadMessagesDto readMessages)
        {
            if (readMessages == null)
            {
                ModelState.AddModelError($"{nameof(readMessages)}", "Incoming data is null");
                return(BadRequest(ModelState));
            }

            foreach (var messageId in readMessages.ReadMessages)
            {
                var messageInChatInfo = new CMessageInChatInfo(
                    default(Guid),
                    messageId,
                    default(Guid),
                    default(Guid),
                    readMessages.UserId,
                    true
                    );

                var rowsAffected = _messageInChatDataProvider.UpdateReadMessageInChat(messageInChatInfo);

                if (rowsAffected == 0)
                {
                    s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({readMessages})", new Exception("Failed to update message in chat"));
                    return(InternalServerError());
                }
            }

            return(Ok(true));
        }
 //public Task<Boolean> ReadMessages(Guid userId, Guid chatId, List<Guid> readMessages)
 public Task <Boolean> ReadMessages(Guid userId, List <Guid> readMessages)
 {
     //_logger.LogInfo($"Supplier method '{nameof(ReadMessages)}({userId}, {chatId}, {readMessages})' is called");
     _logger.LogInfo($"Supplier method '{nameof(ReadMessages)}({userId}, {readMessages})' is called");
     return(Task.Run <Boolean>(() =>
     {
         //var readMessagesDto = new CReadMessagesDto(userId, chatId, readMessages);
         var readMessagesDto = new CReadMessagesDto(userId, readMessages);
         return _service.ReadMessages(readMessagesDto);
     }));
 }
Exemple #3
0
        public Boolean ReadMessages(CReadMessagesDto readMessagesDto)
        {
            try
            {
                HttpResponseMessage response = _client.PostAsync(
                    $"api/chats/messages/read",
                    new StringContent(JsonConvert.SerializeObject(readMessagesDto), Encoding.UTF8, "application/json")
                    ).Result;

                return(response.IsSuccessStatusCode
                    ? response.Content.ReadAsAsync <Boolean>().Result
                    : false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }