Exemplo n.º 1
0
        public void LetInVisitor(string connectionId, string name = "", string url = "")
        {
            try
            {
                var user = _db.Users.Where(u => u.UserName == name).FirstOrDefault();

                var connection = new Connection()
                {
                    ConnectionID   = connectionId,
                    UserAgent      = url,
                    Connected      = true,
                    ConnectionDate = DateTime.Now,
                    User           = user ?? new User()
                    {
                        UserName = name
                    }
                };

                _db.Connections.Add(connection);

                _db.SaveChanges();
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex, ex.Message);
            }
        }
Exemplo n.º 2
0
        public async Task <bool> SaveAccessURLForUser(string url, ClaimsPrincipal user)
        {
            try
            {
                if (!string.IsNullOrEmpty(url))
                {
                    var u = await _userManager.GetUserAsync(user);

                    int count = await GetAccessCount(user);

                    if (count >= 5)
                    {
                        throw new InvalidOperationException("Access limit is full.");
                    }

                    _db.ApplicationFeatures.Add(new ApplicationFeature()
                    {
                        ApplicationUserId = u.Id,
                        URL        = url,
                        Key        = GenerateKey(),
                        CreateDate = DateTimeOffset.Now
                    });

                    _db.SaveChanges();
                    return(true);
                }
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex, $"Unable to save URL. Detail: {ex.Message}");
            }

            return(false);
        }
Exemplo n.º 3
0
        public bool SaveMessage(string connectionId, Message message)
        {
            try
            {
                var currentConnection = _db.Connections.Where(c => c.ConnectionID == connectionId && c.Connected).FirstOrDefault();
                if (currentConnection != null)
                {
                    if (currentConnection.Messages == null)
                    {
                        currentConnection.Messages = new List <Message>();
                    }

                    message.Date = DateTime.Now;
                    currentConnection.Messages.Add(message);

                    _db.Connections.Update(currentConnection);
                    _db.SaveChanges();
                    return(true);
                }
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex, ex.Message);
            }
            return(false);
        }
Exemplo n.º 4
0
        private string CreateMessage(string from, string message, string to = "")
        {
            if (!string.IsNullOrEmpty(to))
            {
                var currentConnection = _db.Connections.Where(c => c.ConnectionID == Context.ConnectionId && c.Connected).First();

                if (currentConnection.Messages == null)
                {
                    currentConnection.Messages = new List <Message>();
                }
                currentConnection.Messages.Add(new Message()
                {
                    Content = message,
                    Date    = DateTime.Now,
                    ToUser  = to
                });

                _db.Connections.Update(currentConnection);
                _db.SaveChanges();
            }

            var image = "http://placehold.it/50/FA6F57/fff&text=WU";//Some custom image for WebUser


            if (from == _configuration["HostUser:Name"])
            {
                image = _configuration["HostUser:Image"];
            }

            var messageContainer = "<span class=\"chat-img pull-left\">"
                                   + $"          <img src=\"{image}\" alt=\"User\" class=\"img-circle\" />"
                                   + "     </span>"
                                   + "     <div class=\"chat-body clearfix\">"
                                   + "         <div class=\"header\">"
                                   + $"             <small class=\"text-muted\"><span class=\"glyphicon glyphicon-time\"></span>{DateTime.Now.ToShortTimeString()}</small>"
                                   + $"             <strong class=\"pull-right primary-font\">{from}</strong>"
                                   + "        </div>"
                                   + $"         <p>{message}"
                                   + "         </p>"
                                   + "     </div>";

            return(messageContainer);
        }