Пример #1
0
        public async Task CreateAnonChat(string name, string email, string phone, string url)
        {
            FreeGeoIPClient ipClient = new FreeGeoIPClient();
            var             ip       = _accessor.HttpContext?.Connection?.RemoteIpAddress?.ToString();
            var             usr      = new AnonymousUser()
            {
                connectionID = Context.ConnectionId, IP = ip, Name = name, Phone = phone, Email = email, LastActiveTime = DateTime.Now, isActive = true, Site = url
            };

            try
            {
                FreeGeoIPCore.Models.Location location = ipClient.GetLocation(ip).Result;
                usr.country = location.CountryName;
                usr.city    = location.City;
            }
            catch (Exception e)
            {
            }
            finally
            {
                usr.country = "-";
                usr.city    = "-";
            }
            _dbContext.anonusers.Add(usr);

            _dbContext.SaveChanges();

            var loggedinUsers = _dbContext.singleActiveUsers.ToList();

            foreach (var loggeduser in loggedinUsers)
            {
                await Groups.AddToGroupAsync(loggeduser.ConnectionID, usr.ID);

                var newgrp = new grouplistresponse {
                    city = usr.city, country = usr.country, anonid = usr.ID, IP = ip, name = usr.Name, newMessageseen = usr.seenByUser, lastTime = TimeAgo(usr.LastActiveTime), active = usr.isActive, email = usr.Email, phone = usr.Phone, site = usr.Site
                };
                await Clients.Client(loggeduser.ConnectionID).SendAsync("newGroup", Newtonsoft.Json.JsonConvert.SerializeObject(newgrp));
            }
            _dbContext.SaveChanges();
            await Clients.Caller.SendAsync("myid", usr.connectionID, true);

            await Groups.AddToGroupAsync(Context.ConnectionId, usr.ID);
        }
        public IActionResult Index(double lon, double lat)
        {
            FreeGeoIPClient clientIP = new FreeGeoIPClient();

            string ipAdd = WeatherGeolocation.GetIPRequest(_httpConAccessor);

            FreeGeoIPCore.Models.Location location = clientIP.GetLocation(ipAdd).Result;

            GeoCoordinate geoCoordinate = new GeoCoordinate();

            if (lon == 0 && lat == 0)
            {
                geoCoordinate.Longitude = location.Longitude;
                geoCoordinate.Latitude  = location.Latitude;
            }
            else
            {
                geoCoordinate.Longitude = lon;
                geoCoordinate.Latitude  = lat;
            }
            return(View());
        }