public IActionResult MarkAsScheduled(int id)
        {
            UserParks found = _context.UserParks.Where(x => x.UsersParkIds == id).First();

            found.ParkVisited           = null;
            _context.Entry(found).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _context.Update(found);
            _context.SaveChanges();

            return(RedirectToAction("CheckUserPrefs"));
        }
        public IActionResult UpdateUserInfo(UserInfo userinfo)
        {
            string   id    = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            UserInfo found = _context.UserInfo.Where(x => x.OwnerId == id).First();

            if (found != null)
            {
                found.Name    = userinfo.Name;
                found.Smoker  = userinfo.Smoker;
                found.Drinker = userinfo.Drinker;
                found.Country = userinfo.Country;
                _context.Entry(found).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                _context.Update(found);
                _context.SaveChanges();
                ViewBag.userName = (string)found.Name;
                return(RedirectToAction("Index", "Home"));
            }
            ViewBag.updateUserError = "USER NOT FOUND... PLEASE CLICK LINK TO ADD USER INFO BEFORE TRYING TO UPDATE";
            return(View("UpdateUserInfo"));
        }
Exemple #3
0
        public IActionResult UpdateParkVisited(int id)
        {
            string Userid = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            UserParks found = _context.UserParks.Where(x => x.UsersParkIds == id).First();

            found.ParkVisited           = true;
            _context.Entry(found).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _context.Update(found);
            _context.SaveChanges();

            return(RedirectToAction("parksVisited"));
        }
        public async Task LifeExpectancyCalc()
        {
            int year = 2016;

            string id = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            UserInfo found = _context.UserInfo.Where(x => x.OwnerId == id).First();

            if (found != null)
            {
                //get the ageGroup that corresponds to the options available in the API using the calculated age in the database
                string ageGroup = GetAgeGroup((int)found.Age);

                //we create an new HttpClient
                //calling the API
                var client = new HttpClient();

                //specify the base address
                client.BaseAddress = new Uri("http://apps.who.int/gho/athena/api/GHO/");

                //specify the endpoint we want to use in our API call
                var response = await client.GetAsync($"LIFE_0000000035.json?filter=COUNTRY:{found.Country};Agegroup:{ageGroup};SEX:{found.Gender};YEAR:{year}");

                //parse the json into the appropriate class in our models
                var life = await response.Content.ReadAsAsync <LifeRootobject>();

                int timeLeft = (int)Math.Round((double)life.fact[0].value.numeric);

                timeLeft = Smoker((bool)found.Smoker, timeLeft);

                timeLeft                    = Drinker((bool)found.Drinker, timeLeft);
                found.LifeExpectancy        = timeLeft;
                _context.Entry(found).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                _context.Update(found);
                await _context.SaveChangesAsync();
            }
        }