Esempio n. 1
0
        /// <summary>
        /// Process new chat.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task <ChatResponse> ProcessNewChat(NewChatDto data)
        {
            var users = await GetChatUsers(data.Users, data.AdminId);

            data.ApplicationUsers = users;

            var chat = _mapper.Map <Chat>(data);

            chat.ApplicationUserChats = SetChatUsers(chat, users);

            var success = await _repository.SaveChat(chat);

            if (!success)
            {
                return(ChatResponse.Unsuccessful("Error saving chat."));
            }

            return(ChatResponse.Successfull(chat));
        }
Esempio n. 2
0
        public async Task <IActionResult> PostNewChat(NewChatDto data)
        {
            var userId = User.FindFirst("UserId")?.Value;

            if (string.IsNullOrEmpty(userId))
            {
                return(BadRequest("Logged User Not Found."));
            }

            data.AdminId = userId;

            var response = await _chatsManager.ProcessNewChat(data);

            if (!response.Success)
            {
                return(BadRequest(response.ErrorMessage));
            }

            var chatId = response.Chat.ChatId.ToString();

            return(Ok(new { chatId }));
        }