Example #1
0
        public async Task Send <T>(T message, User to, User from) where T : class
        {
            var json = JsonConvert.SerializeObject(message);

            var user = await _userManager.Users.FirstOrDefaultAsync(u => u == to);

            if (user != null)
            {
                var newMessage = await _messengerContext.AddAsync(new Message()
                {
                    From  = from.Id,
                    Level = MessageLevel.Normal,
                    Test  = json
                });

                user.AddMessagesID(newMessage.Entity.Id);

                await _messengerContext.SaveChangesAsync();

                await _userManager.UpdateAsync(user);
            }
        }