Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "UserId,FirstName,LastName,Address,TelephoneNumber,Email")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Ejemplo n.º 2
0
        public ActionResult AddOrEdit(Admin adminModel)
        {
            using (GymAppDBEntities dbc = new GymAppDBEntities())
            {
                if (dbc.Admins.Any(x => x.Username == adminModel.Username))
                {
                    ViewBag.DuplicateMessage = $"User {adminModel.Username} already exists.";
                    return(View("AddOrEdit", adminModel));
                }

                dbc.Admins.Add(adminModel);
                dbc.SaveChanges();
            }
            ModelState.Clear();
            ViewBag.SuccessMessage = $"Registration of {adminModel.Username} Successful.";
            return(View("AddOrEdit", new Admin()));
        }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "HealthRecordId,UserId,Age,Weight,Height")] HealthRecord healthRecord, int gender, int exFrequency)
        {
            bool error = true;

            #region Calculations
            // BMI CALUCULATIONS
            double bmi = Math.Round((((double)healthRecord.Weight / (double)healthRecord.Height / (double)healthRecord.Height) * 10000), 2);
            healthRecord.BMI = (decimal)bmi;
            // BMR
            if (gender == 1)// Female
            {
                double bmr = Math.Round(447.593 + (9.247 * (double)healthRecord.Weight) + (3.098 * (double)healthRecord.Height) - (4.330 * (double)healthRecord.Age), 2);
                healthRecord.BMR = (decimal)bmr;
            }
            else // Male (Default)
            {
                double bmr = Math.Round(88.362 + (13.397 * (double)healthRecord.Weight) + (4.799 * (double)healthRecord.Height) - (5.677 * (double)healthRecord.Age), 2);
                healthRecord.BMR = (decimal)bmr;
            }

            //Kcal
            double Kcal = CalculateKcal(exFrequency, (decimal)healthRecord.BMR);
            healthRecord.KCAL = (decimal)Kcal;

            #endregion

            HealthRecord existingHealthRecord = db.HealthRecords.Where(hr => hr.UserId == healthRecord.UserId).FirstOrDefault();
            if (existingHealthRecord != null)
            {
                //update
                existingHealthRecord.Age    = healthRecord.Age;
                existingHealthRecord.Height = healthRecord.Height;
                existingHealthRecord.Weight = healthRecord.Weight;
                existingHealthRecord.BMI    = healthRecord.BMI;
                existingHealthRecord.BMR    = healthRecord.BMR;
                existingHealthRecord.KCAL   = healthRecord.KCAL;
                db.SaveChanges();
                error = false;
            }
            else
            {
                //add
                db.HealthRecords.Add(healthRecord);
                db.SaveChanges();
                error = false;
            }
            if (error)
            {
                return(RedirectToAction("Index"));
            }

            if (ModelState.IsValid)
            {
                //db.HealthRecords.Add(healthRecord);
                //db.SaveChanges();
                //return RedirectToAction("Index");
                ModelState.Clear();
            }


            //ViewBag.UserId = new SelectList(db.Users, "UserId", "FirstName", healthRecord.UserId);
            //return View(healthRecord);
            return(RedirectToAction("Index"));
        }