public async Task <ActionResult> Register(RegisterViewModel model)
        {
            var db = new ApplicationDbContext();

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, UserRoleId = 1
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    var editUser = db.Users.FirstOrDefault(x => x.UserName == model.UserDisplayName);
                    if (editUser != null)
                    {
                        var ipTracker = new IpTracker();
                        editUser.UserDisplayName      = model.UserDisplayName;
                        editUser.UserTitel            = "Test123";
                        editUser.UserSignature        = "Test456";
                        editUser.UserLocation         = model.UserLocation;
                        editUser.UserRealName         = model.UserRealName;
                        editUser.UserUrl              = model.UserUrl;
                        editUser.UserSteam            = model.UserSteam;
                        editUser.UserRegistrationIp   = ipTracker.GetIpAddress();
                        editUser.UserDateOfBirth      = model.UserDateOfBirth.ToUnix();
                        editUser.UserRegistrationDate = DateTime.UtcNow.ToUnix();
                        db.Entry(editUser);
                        db.SaveChanges();
                    }

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Example #2
0
        //GET: ForecastApp/SearchCity
        public IActionResult SearchCity(double longitude, double latitude)
        {
            IpStackClient ipClient = new IpStackClient(_config["Keys:IPStack"]);

            string ipAddress = LeadHornet.Models.weather.GetRequestIP(_httpContextAccessor);

            IpStack.Models.IpAddressDetails location = ipClient.GetIpAddressDetails(ipAddress);

            GeoCoordinate coordinate = new GeoCoordinate();

            // If location is provided then use over IP address
            if (longitude == 0 && latitude == 0)
            {
                coordinate.Longitude = location.Longitude;
                coordinate.Latitude  = location.Latitude;
            }
            else
            {
                coordinate.Longitude = longitude;
                coordinate.Latitude  = latitude;
            }

            MetOfficeDataPointClient metClient = new MetOfficeDataPointClient(_config["Keys:MetOfficeDataPoint"]);

            MetOfficeDataPoint.Models.Location site             = metClient.GetClosestSite(coordinate).Result;
            ForecastResponse3Hourly            forecastResponse = metClient.GetForecasts3Hourly(null, site.ID).Result;

            // Create list containing 5 days of forecasts for midday
            List <WeatherSummary> weatherSummaries = new List <WeatherSummary>();

            // Get current minutes after midnight
            int minutes = (int)(DateTime.Now.TimeOfDay.TotalSeconds / 60);

            foreach (ForecastLocation3Hourly forecastLocation in forecastResponse.SiteRep.DV.Location)
            {
                foreach (Period3Hourly period in forecastLocation.Period)
                {
                    if (DateTime.Parse(period.Value).Date == DateTime.Today.Date)
                    {
                        WeatherSummary weatherSummary = new WeatherSummary();
                        weatherSummary.ForecastDay = DateTime.Parse(period.Value);

                        // Find closest forecast to now
                        Rep3Hourly forecast = period.Rep.Aggregate((x, y) => Math.Abs(x.MinutesAfterMidnight - minutes) < Math.Abs(y.MinutesAfterMidnight - minutes) ? x : y);
                        weatherSummary.Icon = LeadHornet.Models.weather.GetWeatherIcon(forecast.WeatherType);
                        // Find min temperature
                        weatherSummary.MinTemperature = (int)period.Rep.Where(x => x.MinutesAfterMidnight >= forecast.MinutesAfterMidnight).Min(x => x.Temperature);
                        // Find current temperature
                        weatherSummary.MaxTemperature = (int)period.Rep.Where(x => x.MinutesAfterMidnight >= forecast.MinutesAfterMidnight).Max(x => x.Temperature);
                        // Get remaing forecasts
                        weatherSummary.Forecasts = period.Rep.Where(x => x.MinutesAfterMidnight >= forecast.MinutesAfterMidnight).ToList();

                        weatherSummaries.Add(weatherSummary);
                    }
                    else
                    {
                        WeatherSummary weatherSummary = new WeatherSummary();
                        weatherSummary.ForecastDay = DateTime.Parse(period.Value);

                        // Get icon for midday
                        weatherSummary.Icon = LeadHornet.Models.weather.GetWeatherIcon(period.Rep.First(x => x.MinutesAfterMidnight == 720).WeatherType);
                        // Find min temperature
                        weatherSummary.MinTemperature = (int)period.Rep.Min(x => x.Temperature);
                        // Find max temperature
                        weatherSummary.MaxTemperature = (int)period.Rep.Max(x => x.Temperature);
                        // Get forecasts
                        weatherSummary.Forecasts = period.Rep;

                        weatherSummaries.Add(weatherSummary);
                    }
                }
            }

            ViewData["WeatherSummaries"] = weatherSummaries;
            ViewData["Location"]         = location;
            ViewData["Site"]             = site;

            string strLoc           = location.CountryName;
            string strIP            = location.Ip;
            string strCountryCode   = location.CountryCode;
            string strContinentName = location.ContinentName;

            var ipTrackerData = new IpTracker();

            _leadHornetDbContext.IpTrackers.Add(new IpTracker()
            {
                location        = strLoc,
                Ip              = strIP,
                CountryCode     = strCountryCode,
                ContinentName   = strContinentName,
                DateTimeVisited = DateTime.Now
            });

            _leadHornetDbContext.SaveChanges();

            return(View());
        }