public Task <Boolean> CreateChat(CChatData chatData, Guid creatorId, List <Guid> participantsId)
        {
            _logger.LogInfo($"Supplier method '{nameof(CreateChat)}({chatData}, {creatorId}, {participantsId})' is called");

            CNewChatDto chatDto = new CNewChatDto(chatData.Title, chatData.IsPersonal, (Int32)chatData.Type, creatorId, participantsId);

            return(Task.Run <Boolean>(() => _service.CreateChat(chatDto)));
        }
Exemple #2
0
        public Boolean CreateChat(CNewChatDto chatDto)
        {
            try
            {
                HttpResponseMessage response = _client.PostAsync(
                    $"api/chats/new",
                    new StringContent(JsonConvert.SerializeObject(chatDto), Encoding.UTF8, "application/json")).Result;

                return((response.IsSuccessStatusCode)
                    ? response.Content.ReadAsAsync <Boolean>().Result
                    : false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemple #3
0
        public IHttpActionResult PostChat([FromBody] CNewChatDto newChat)
        {
            s_log.LogInfo($"{System.Reflection.MethodBase.GetCurrentMethod()}({newChat}) is called");

            if (newChat == null)
            {
                s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({(CNewChatDto)null})", new ArgumentNullException(nameof(newChat), "Incoming data is null"));
                ModelState.AddModelError($"{nameof(newChat)}", "Incoming data is null");
                return(BadRequest(ModelState));
            }

            var chatInfo = _chatDataProvider.CreateChat(new CChatInfo(default(Guid), newChat.Title, newChat.CreatorId, newChat.IsPersonal, newChat.Type));

            if (chatInfo == null)
            {
                s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({newChat})", new Exception("Failed to create chat"));
                return(InternalServerError());
            }

            var result =
                _chatsParticipantDataProvider.CreateChatParticipant(
                    new CChatsParticipantInfo(default(Guid), chatInfo.Id, newChat.CreatorId));

            if (result == 0)
            {
                s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({newChat})", new Exception("Failed to create chat"));
                return(InternalServerError());
            }

            foreach (var participantId in newChat.ParticipantsId)
            {
                result =
                    _chatsParticipantDataProvider.CreateChatParticipant(
                        new CChatsParticipantInfo(default(Guid), chatInfo.Id, participantId));

                if (result == 0)
                {
                    s_log.LogError($"{System.Reflection.MethodBase.GetCurrentMethod()}({newChat})", new Exception("Failed to create chat"));
                    return(InternalServerError());
                }
            }

            return(Ok(true));
        }