Example #1
0
        public async Task DeleteChat(int id)
        {
            var chat = _context.Chats.Where(x => x.Id == id).FirstOrDefault();

            _context.Chats.Remove(chat);

            await _context.SaveChangesAsync();
        }
Example #2
0
        public async Task <MessageViewModel> ReturnSendedMessageAsync(int groupId, string message)
        {
            var newMessage = new Message
            {
                ChatId    = groupId,
                Timestamp = DateTime.Now,
                Text      = message,
                Name      = _httpContextAccessor.HttpContext.User.Identity.Name
            };

            _context.Messages.Add(newMessage);
            await _context.SaveChangesAsync();

            var messageView = _mapper.Map <MessageViewModel>(newMessage);

            return(messageView);
        }
        public async Task <IActionResult> CreateMessageAsync(int groupId, string message)
        {
            var newMessage = new Message
            {
                ChatId    = groupId,
                Timestamp = DateTime.Now,
                Text      = message,
                Name      = User.Identity.Name
            };

            _context.Messages.Add(newMessage);
            await _context.SaveChangesAsync();

            return(RedirectToAction("GetChat", new { id = groupId }));
        }
Example #4
0
        public override async Task OnConnectedAsync()
        {
            var userName = Context.User.Identity.Name;

            var user = _context.Users.Include(x => x.Connections).Where(x => x.UserName == userName).FirstOrDefault();

            var connection = new Connection
            {
                ConnectionID = GetConnectionId(),
                Connected    = true
            };

            user.Connections.Add(connection);

            await _context.SaveChangesAsync();

            await base.OnConnectedAsync();
        }