Exemplo n.º 1
0
        public ActionResult Save(BmiViewModel bmi)
        {
            //get currently user loged in throught the ASP.Net Users table
            var currentUserId = User.Identity.GetUserId();

            BmiModel userId = new BmiModel()
            {
                UserId = currentUserId
            };

            //adds user logged in to BmiModel table under UserId
            bmi.BmiModel.UserId = userId.UserId;

            if (!ModelState.IsValid)
            {
                return(View("CalculateBmi"));
            }

            if (bmi.BmiModel.Id == 0)
            {
                _context.BmiModel.Add(bmi.BmiModel);
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "BMI"));
        }
Exemplo n.º 2
0
        public ActionResult CalculateBmi()
        {
            BmiViewModel viewModel = new BmiViewModel()
            {
                BmiModel = new BmiModel()
            };

            return(View("CalculateBmi", viewModel));
        }
Exemplo n.º 3
0
 public void SetUp()
 {
     vm = new BmiViewModel();
 }