private void btn_SaveAll_Click(object sender, RoutedEventArgs e) { using (var dbc = new GymAppDBEntities()) { User CurrentUser = dbc.Users.Where(u => u.UserId == CurrentUserId).FirstOrDefault <User>(); HealthRecord CurrentRecord = dbc.HealthRecords.Where(r => r.HealthRecordId == CurrentHealthRecordId).FirstOrDefault <HealthRecord>(); // BMI CALUCULATIONS double bmi = Math.Round(((CurrentWeight / CurrentHeight / CurrentHeight) * 10000), 2); CurrentRecord.BMI = (decimal)bmi; BMI_Value.Text = CurrentRecord.BMI.ToString(); // BMR Calculation Formula if (rdo_Female.IsChecked == true) { double bmr = Math.Round(447.593 + (9.247 * CurrentWeight) + (3.098 * CurrentHeight) - (4.330 * CurrentAge), 2); CurrentRecord.BMR = (decimal)bmr; BMR_Value.Text = CurrentRecord.BMR.ToString(); } else if (rdo_Male.IsChecked == true) { double bmr = Math.Round(88.362 + (13.397 * CurrentWeight) + (4.799 * CurrentHeight) - (5.677 * CurrentAge), 2); CurrentRecord.BMR = (decimal)bmr; BMR_Value.Text = CurrentRecord.BMR.ToString(); } dbc.SaveChanges(); MessageBox.Show($"User: {CurrentUser.FirstName} , health calculations added!"); Tab3.IsSelected = true; } }
//----------------------------- ALL KCAL FUNCTIONS-------------------------------// public double CalculateKcal(decimal cal) { using (var dbc = new GymAppDBEntities()) { HealthRecord CurrentRecord = dbc.HealthRecords.Where(r => r.HealthRecordId == CurrentHealthRecordId).FirstOrDefault <HealthRecord>(); if (CurrentRecord.BMR != null) { double Kcal = (double)(CurrentRecord.BMR * cal); CurrentRecord.KCAL = (decimal)Kcal; return(Kcal); } } return(0); }
private void btn_Submit_Click(object sender, RoutedEventArgs e) { Tab2.IsSelected = true; using (var dbc = new GymAppDBEntities()) { //adding a user var userToAdd = new User(); userToAdd.FirstName = txt_FirstName.Text; userToAdd.LastName = txt_LastName.Text; userToAdd.Address = txt_Address.Text; userToAdd.Email = txt_Email.Text; userToAdd.TelephoneNumber = txt_Mobile.Text; //adding a health record var healthInfoToAdd = new HealthRecord(); healthInfoToAdd.UserId = userToAdd.UserId; healthInfoToAdd.Age = int.Parse(txt_Age.Text); healthInfoToAdd.Height = decimal.Parse(txt_Height.Text); healthInfoToAdd.Weight = decimal.Parse(txt_Weight.Text); //update db dbc.Users.Add(userToAdd); dbc.HealthRecords.Add(healthInfoToAdd); dbc.SaveChanges(); //saving locally CurrentHealthRecordId = healthInfoToAdd.HealthRecordId; CurrentUserId = userToAdd.UserId; CurrentAge = (double)healthInfoToAdd.Age; CurrentWeight = (double)healthInfoToAdd.Weight; CurrentHeight = (double)healthInfoToAdd.Height; MessageBox.Show($"User: {userToAdd.FirstName} , successfully added!"); } }