public async Task <IActionResult> CreateChat() { var userId = User.Claims.ToList()[0].Value; await _chatRep.CreateChat(userId); return(Ok()); }
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 })); }
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); }
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); }
public long InitiateChatWithUser(long userId, long collocutorId) { ChatEntity chatEntity = _repository.GetChatByUsers(userId, collocutorId); if (chatEntity == null) { chatEntity = _repository.CreateChat(userId, collocutorId); } return(chatEntity.Id); }
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); }
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)); }
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); }
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)); }
public JsonResult PostChat([FromBody] GroupChatVM G) { int?id = repository.CreateChat(G); return(Json(id)); }