示例#1
0
        public async Task <IActionResult> CreateChat()
        {
            var userId = User.Claims.ToList()[0].Value;
            await _chatRep.CreateChat(userId);

            return(Ok());
        }
示例#2
0
        public async Task <IActionResult> CreateGroupChat(GroupChatDTO dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Bad Request"));
            }

            if (!int.TryParse(dto.OwnerId, out int ownerIdFormatted))
            {
                return(BadRequest("Incorrect format id."));
            }

            var chat = await _repository.CreateChat(Types.ChatType.GroupChat, ownerIdFormatted, dto.Name).ConfigureAwait(true);

            if (chat == null)
            {
                return(BadRequest("Bad result. Sory"));
            }

            return(Ok(new ChatDTO
            {
                Id = chat.Id,
                Name = chat.Name,
                OwnerId = chat.OwnerId,
                Type = chat.Type
            }));
        }
示例#3
0
        private async Task <string> UpdateOrCreateChat()
        {
            Chat   chat             = null;
            string notificationDesc = string.Empty;

            if (_type.Equals(NotificationType.Invitation))
            {
                await AddFriend().ConfigureAwait(true);

                chat = await _repository.CreateChat(ChatType.FriendsChat, _requester).ConfigureAwait(true);

                notificationDesc = $"User {_currentUser.Email} accepted your invitation.";
            }
            else
            {
                chat = await GetChat().ConfigureAwait(true);

                if (chat == null)
                {
                    throw new ArgumentNullException("Chat is null");
                }

                notificationDesc = $"User {_currentUser.Email} accepted invitation to {chat.Name} chat.";
            }

            await _repository.CreateChatMemberships(_requester, _currentUser, chat).ConfigureAwait(true);

            return(notificationDesc);
        }
示例#4
0
        public async Task <ChatDTO> CreateChat(ChatCreateDTO chat)
        {
            var mappedChat  = _mapper.Map <Chat>(chat);
            var createdChat = await _chatRepository.CreateChat(mappedChat);

            var returnedChat = _mapper.Map <ChatDTO>(createdChat);

            return(returnedChat);
        }
示例#5
0
        public long InitiateChatWithUser(long userId, long collocutorId)
        {
            ChatEntity chatEntity = _repository.GetChatByUsers(userId, collocutorId);

            if (chatEntity == null)
            {
                chatEntity = _repository.CreateChat(userId, collocutorId);
            }

            return(chatEntity.Id);
        }
示例#6
0
        public void AddRelation(long userId, long friendId)
        {
            var newRelation = new Relation()
            {
                UserOneId = userId,
                UserTwoId = friendId
            };

            _context.Set <Relation>().Add(newRelation);
            Save();

            _chatRepository.CreateChat(userId, friendId);
        }
示例#7
0
        public ActionResult Chat(int?id)
        {
            if (id == null || Session["accountId"] == null)
            {
                return(RedirectToAction("LogIn", "Accounts"));
            }
            Chat chat = new Chat();

            chat.AccountId = (int)Session["accountId"];
            int     contactlistId = (int)Session["contactlistId"];
            Contact contact       = contRep.GetContact(contactlistId, friendId: (int)id);

            if (contact == null)
            {
                return(RedirectToAction("Index", "Contacts"));
            }
            else
            {
                chat.ContactId    = contact.FriendId;
                chat.ReceiverName = accRep.GetAccount(chat.ContactId).Name;
            }
            chat.ChatId = chatRep.GetChatId(chat);

            if (chat.ChatId == 0)
            {
                chat = chatRep.CreateChat(chat);
            }
            chat.Messages = (List <Message>)chatRep.GetMessages(chat.ChatId);

            foreach (Message message in chat.Messages)
            {
                message.SenderName = accRep.GetAccount(message.SenderId).Name;
            }
            Session["chatId"] = chat.ChatId;

            return(View(chat));
        }
示例#8
0
        public async Task StartChat(string messageText)
        {
            var users           = userRepository.Users.ToArray();
            var loginedUser     = userRepository.Users.FirstOrDefault(user => user.UserName == Context.User.Identity.Name);
            var usersRequesting = users.Where(user => permissionRepository.CheckPermission(user, "ChatModerating")).Select(user => user.UserName).ToList();

            usersRequesting.Add(loginedUser.UserName);
            var chat = await chatRepository.CreateChat(new Chat()
            {
                UserName = loginedUser.UserName,
                IsOpen   = true,
            }, messageText);

            await Groups.AddToGroupAsync(loginedUser.UserName, GetChatName(chat.ChatId));

            await Clients.Users(usersRequesting).SendAsync("AddNewChat", chat);
        }
示例#9
0
        public ActionResult Create(NewChatModel newChatModel)
        {
            IEnumerable <Contact> contacts = contactRepository.GetAllContacts(((Account)Session["loggedin_account"]).Id);

            ViewBag.Contacts = contacts;
            if (ModelState.IsValid)
            {
                Chat chat = new Chat();
                chat.ChatName = newChatModel.ChatName;
                chat.ChatDesc = newChatModel.ChatDesc;
                chat.Participants.Add(chatRepository.GetAccountById(newChatModel.participant));
                chat.Participants.Add(chatRepository.GetAccountById(((Account)Session["loggedin_account"]).Id));
                chatRepository.CreateChat(chat);

                return(RedirectToAction("Index"));
            }
            return(View(newChatModel));
        }
示例#10
0
        public JsonResult PostChat([FromBody] GroupChatVM G)
        {
            int?id = repository.CreateChat(G);

            return(Json(id));
        }