public HealthProfile Create(HealthProfile healthProfile) { //Add the health profile to the database and save changes _db.HealthProfile.Add(healthProfile); _db.SaveChanges(); return(healthProfile); }
public static void Main() { Console.Write("Please enter your first name: "); string firstName = Console.ReadLine(); Console.Write("Please enter your last name: "); string lastName = Console.ReadLine(); Console.Write("Please enter your gender: "); string gender = Console.ReadLine(); Console.Write("Please enter your month of birth: "); int monOfBirth = Convert.ToInt32(Console.ReadLine()); Console.Write("Please enter your day of birth: "); int dayOfBirth = Convert.ToInt32(Console.ReadLine()); Console.Write("Please enter your year of birth: "); int yearOfBirth = Convert.ToInt32(Console.ReadLine()); Console.Write("Please enter your height in meters: "); double height = Convert.ToDouble(Console.ReadLine()); Console.Write("Please enter your weight in kg: "); double weight = Convert.ToDouble(Console.ReadLine()); HealthProfile me = new HealthProfile(firstName, lastName, gender, monOfBirth, dayOfBirth, yearOfBirth, height, weight); Console.WriteLine("My age is {0}", me.GetAge()); Console.WriteLine("My BMI is {0}", me.GetBMI(me.Weight, me.Height)); Console.WriteLine("My max heart rate is {0}", me.GetMaxHeartRate); Console.WriteLine("My target heart range is {0}-{1}", me.GetMinTargetHeartRate, me.GetMaxTargetHeartRate); }
public void Delete(int id) { HealthProfile healthprofile = _db.HealthProfile.Find(id); _db.HealthProfile.Remove(healthprofile); _db.SaveChanges(); }
public static HealthProfile GetHealthProfile() { var o = new HealthProfile(); o.Height = PhysicalCharacteristics.GetMilHeight(Npc.NpcProfile.BiologicalSex, Npc.NpcProfile.Rank.Branch); o.Weight = PhysicalCharacteristics.GetMilWeight(o.Height, Npc.NpcProfile.Birthdate, Npc.NpcProfile.BiologicalSex, Npc.NpcProfile.Rank.Branch); o.BloodType = PhysicalCharacteristics.GetBloodType(); var mealPreference = string.Empty; if (PercentOfRandom.Does(95)) //x% have a meal preference { mealPreference = ($"config/meal_preferences.txt").GetRandomFromFile(); } o.PreferredMeal = mealPreference; if (PercentOfRandom.Does(98)) //x% have a medical condition { var raw = File.ReadAllText("config/medical_conditions_and_medications.json"); var r = JsonConvert.DeserializeObject <IEnumerable <HealthProfileRecord> >(raw).RandomElement(); var c = new MedicalCondition { Name = r.Condition }; foreach (var med in r.Medications) { c.Prescriptions.Add(new Prescription { Name = med }); } o.MedicalConditions.Add(c); } return(o); }
public void Delete(int id) { //Find the health profile that matches the id. Then, remove it from the database and save changes HealthProfile healthProfile = _db.HealthProfile.Find(id); _db.HealthProfile.Remove(healthProfile); _db.SaveChanges(); }
public IActionResult Edit(HealthProfile healthProfile) { if (ModelState.IsValid) { _bmi.Update(healthProfile.Id, healthProfile); return(RedirectToAction("Index")); } return(View(healthProfile)); }
public IActionResult Create(HealthProfile bmi) { if (ModelState.IsValid) { _bmi.Create(bmi); return(RedirectToAction("Index")); } return(View()); }
static void Main(string[] args) { HealthProfile myProfile = new HealthProfile(); Console.WriteLine("Name: {0}, {1}" + "\nGender: {2}" + "\nBMI: {3}" + "\nMax HR: {4}", myProfile.LastName, myProfile.FirtName, myProfile.Gender, myProfile.GetBMI(), myProfile.MaximumHeartRate()); }
public IActionResult Edit(HealthProfile healthProfile) { //If the model state is valid, update the profile if (ModelState.IsValid) { _healthProfiles.Update(healthProfile.Id, healthProfile); return(RedirectToAction("Index", "Home")); } return(View(healthProfile)); }
public static void Main(string[] args) { string fName, lName, gender; int height, weight; int birthDay, birthMonth, birthYear; //Prompt first name, last name and gender Console.Write("\nEnter your first name: "); fName = Console.ReadLine(); Console.Write("Enter your last name: "); lName = Console.ReadLine(); Console.Write("Enter your gender (Male/Female): "); gender = Console.ReadLine(); //Prompt height and weight Console.Write("Enter your height: "); height = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter your weight: "); weight = Convert.ToInt32(Console.ReadLine()); //Prompt date of birth Console.Write("Enter your day of birth: "); birthDay = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter your month of birth: "); birthMonth = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter your year of birth: "); birthYear = Convert.ToInt32(Console.ReadLine()); //Create an instance of HealthProfile HealthProfile profile = new HealthProfile(fName, lName, gender, birthDay, birthMonth, birthYear, height, weight); //Call setAge profile.setAge(); //Display Info Console.WriteLine("\n\n\nYour information\n------------------"); Console.WriteLine("Name: {0} {1}\nAge: {2}", profile.FirstName, profile.LastName, profile.Age); Console.WriteLine("Gender: {0}\nHeight: {1} inches\nWeight: {2} lbs", profile.Gender, profile.Height, profile.Weight); Console.WriteLine("Max Heart Rate: {0}\nTarget Heart Rate: {1}", profile.getMaxHeartRate(), profile.getTargetHeartRate()); Console.WriteLine("BMI: {0}", profile.getBMI()); Console.WriteLine("\n\n\n{0}\n{1}\n{2}\n{3}\n{4}\n\n", "BMI VALUES", "Underweight: less than 18.5", "Normal: between 18.5 and 24.9", "Overweight: between 25 and 29.9", "Obese: 30 or greater"); }
static void Main(string[] args) { string firstName; string lastName; string gender; int birthMonth; int birthDay; int birthYear; int height; int weight; Console.Write("Enter First Name: "); firstName = Console.ReadLine(); Console.Write("Enter Last Name: "); lastName = Console.ReadLine(); Console.Write("Enter gender (M or F): "); gender = Console.ReadLine(); Console.Write("Enter Birth Month (1-12): "); birthMonth = int.Parse(Console.ReadLine()); Console.Write("Enter Birth Day (1-31): "); birthDay = int.Parse(Console.ReadLine()); Console.Write("Enter Birth Year: "); birthYear = int.Parse(Console.ReadLine()); Console.Write("Enter Height (in inches): "); height = int.Parse(Console.ReadLine()); Console.Write("Enter Weight (in pounds): "); weight = int.Parse(Console.ReadLine()); HealthProfile healthProfile = new HealthProfile(firstName, lastName, gender, birthMonth, birthDay, birthYear, height, weight); Console.WriteLine($"\nHello, {healthProfile.FirstName} {healthProfile.LastName}"); Console.WriteLine($"Gender: {healthProfile.Gender}"); Console.WriteLine($"Date of Birth: {healthProfile.BirthMonth}/{healthProfile.BirthDay}/{healthProfile.BirthYear}"); Console.WriteLine($"Height: {healthProfile.Height}"); Console.WriteLine($"Weight: {healthProfile.Weight}"); Console.WriteLine($"Age: {healthProfile.getAge()}"); Console.WriteLine($"Maximum Heart Rate: {healthProfile.getMaxHeartRate()}"); Console.WriteLine($"Target Heart Rate Range: {healthProfile.getMinTargetRate()}/{healthProfile.getMaxTargetRate()}"); Console.WriteLine($"BMI: {healthProfile.getBMI():F}\n"); Console.WriteLine("BMI Values"); Console.WriteLine("Underweight:\tless than 18.5"); Console.WriteLine("Normal:\t\tbetween 18.5 and 24.9"); Console.WriteLine("Overweight:\tbetween 25 and 29.9"); Console.WriteLine("Obese:\t\t30 or greater\n"); }
internal HealthProfileModel RetrieveHealthProfile(string userId) { HealthProfileModel healthProfile = new HealthProfileModel(); try { HealthProfile healthProfileDb = checkUpContext.HealthProfiles.Where(w => w.userId == userId).FirstOrDefault(); healthProfile.Id = healthProfileDb.Id; healthProfile.dieaseNamesArray = healthProfileDb.DieaseNames.Select(s => s.Name).ToList(); healthProfile.isSTakeantiBiotic = healthProfileDb.isSTakeantiBiotic; healthProfile.isSuffreDiabetes = healthProfileDb.isSuffreDiabetes; healthProfile.isSuffrePressure = healthProfileDb.isSuffrePressure; healthProfile.isTakehaemophilia = healthProfileDb.isTakehaemophilia; healthProfile.userId = userId; } catch (Exception ex) { healthProfile = null; } return(healthProfile); }
public static void Main(string[] args) { HealthProfile hp1 = new HealthProfile(null, null, 0, 0, 0, 0, 0, null); Console.Write("Enter First Name: "); hp1.FirstName = Convert.ToString(Console.ReadLine()); Console.Write("Enter Last Name: "); hp1.LastName = Convert.ToString(Console.ReadLine()); Console.Write("Enter Day of Birth: "); hp1.DayOfBirth = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Month of Birth: "); hp1.MonthOfBirth = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Year of Birth: "); hp1.YearOfBirth = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Weight in pounds: "); hp1.WeightInPounds = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Height in inches: "); hp1.HeightInInches = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Gender: "); hp1.Gender = Convert.ToString(Console.ReadLine()); hp1.DisplayFirstName(); hp1.DisplayLastName(); hp1.DisplayDayOfBirth(); hp1.DisplayMonthOfBirth(); hp1.DisplayYearOfBirth(); hp1.DisplayWeightInPounds(); hp1.DisplayHeightInInches(); hp1.DisplayGender(); hp1.DisplayYearsOfAgeSimple(); hp1.DisplayMaxHeartRate(); hp1.DisplayTargetHeartRate(); hp1.DisplayBodyMassIndex(); hp1.DisplayBMIOutput(); hp1.DisplayBMIChart(); }
static void Main() { // An object of CultureInfo class to store regional settings. We need it to make dot a decimal mark. CultureInfo cultureEnUs = new CultureInfo("en-US"); // Prompt user to enter first name. Console.WriteLine("Please enter person's first name: "); // Declare variable to store person's first name and assign user input to it. string fName = Console.ReadLine(); // Prompt user to enter last name. Console.WriteLine("Please enter person's last name: "); // Declare variable to store person's last name and assign user input to it. string lName = Console.ReadLine(); // Prompt user to enter gender. Console.WriteLine("Please enter person's gender (use \"true\" for male and \"false\" for female): "); // Declare variable to store person's gender and assign user input to it. bool gender = bool.Parse(Console.ReadLine()); // Prompt user to enter birth year. Console.WriteLine("Please enter person's birth year: "); // Get a line of text from user, cast it to integer type and assign the result to a variable just declared. int bYear = int.Parse(Console.ReadLine()); // Prompt user to enter birth month. Console.WriteLine("Please enter person's birth month (in digital form): "); // Get a line of text from user, cast it to integer type and assign the result to a variable just declared. int bMonth = int.Parse(Console.ReadLine()); // Prompt user to enter birth day. Console.WriteLine("Please enter person's birth day (in digital form): "); // Get a line of text from user, cast it to integer type and assign the result to a variable just declared. int bDay = int.Parse(Console.ReadLine()); // Prompt user to enter height. Console.WriteLine("Please enter person's height (in meters): "); /* Get a line of text from user, cast it to double type and assign the result to a variable just declared. We use cultureEnUs object as a second parameter of Parse method to make sure that the application would recognise number with dot as a decimal mark. */ double height = double.Parse(Console.ReadLine(), cultureEnUs); // Prompt user to enter weight. Console.WriteLine("Please enter person's weight (in kilograms): "); /* Get a line of text from user, cast it to double type and assign the result to a variable just declared. We use cultureEnUs object as a second parameter of Parse method to make sure that the application would recognise number with dot as a decimal mark. */ double weight = double.Parse(Console.ReadLine(), cultureEnUs); /* Now, when we got all the information we needed, we can create an object of class HealthProfile and pass all got values as parameters to class constructor. */ HealthProfile person = new HealthProfile(fName, lName, gender, bYear, bMonth, bDay, height, weight); // Print empty line for clearer output. Console.WriteLine(); // Display person's first and last name. Console.WriteLine($"Health profile for {person.FirstName} {person.LastName}"); // To display person's gender we need to use if construction. I hope that the next chapter will introduce IF-ELSE statement. :) // If person is male. if (person.Gender == true) { Console.WriteLine("Gender: Male"); } // If person is not male (i.e. female). if (person.Gender == false) { Console.WriteLine("Gender: Female"); } /* Display person's birth date using international standard date notation (YYYY-MM-DD). * https://en.wikipedia.org/wiki/ISO_8601 */ Console.WriteLine($"Birth date: {person.BirthYear}-{person.BirthMonth}-{person.BirthDay}"); // Display person's height and weight. Console.WriteLine($"Height: {(person.HeightInMeters).ToString(cultureEnUs)}m"); Console.WriteLine($"Weight: {person.WeightInKilograms}kg"); Console.WriteLine($"Age: {person.AgeInYears()} years"); Console.WriteLine( $"Body mass index (BMI): {(person.WeightInKilograms / (person.HeightInMeters * person.HeightInMeters)).ToString(cultureEnUs)}"); Console.WriteLine($"Maximum heart rate: {person.MaxHeartRate()}"); Console.WriteLine($"Target heart rate range: {person.MinTargetHeartRate()}-{person.MaxTargetHeartRate()}"); // Print empty line for clearer output. Console.WriteLine(); // Display BMI reference information. Console.WriteLine("BMI values"); Console.WriteLine("Underweight: less than 18.5"); Console.WriteLine("Normal: between 18.5 and 24.9"); Console.WriteLine("Overweight: between 24.9 and 29.9"); Console.WriteLine("Obese: 30 or greater"); }
public static void Main(string[] args) { string firstName, // variable to hold first name lastName, // variable to hold last name gender; // variable to hold gender int monthBorn, // variable to hold month of birth dayBorn, // variable to hold day of birth yearBorn, // variable to hold year of birth height, // variable to hold height in inches weight; // variable to hold weight in pounds // user info Console.WriteLine("Welcome to the Health Profile Application."); Console.WriteLine("This application provides a health profile based on personal information."); Console.WriteLine("\nPersonal Information"); // prompt user to input first name Console.Write("Enter your first name (John): "); firstName = Console.ReadLine(); // prompt user to input last name Console.Write("Enter your last name (Doe): "); lastName = Console.ReadLine(); // prompt user to input gender Console.Write("Enter your gender: "); gender = Console.ReadLine(); // prompt user to input month of birth Console.WriteLine("\nMonth Numbers: Jan = 1, Dec = 12"); Console.Write("Enter the month number of the month you were born: "); monthBorn = Convert.ToInt32(Console.ReadLine()); // prompt user to input day of birth Console.Write("Enter the day number for the day you were born (1 to 31): "); dayBorn = Convert.ToInt32(Console.ReadLine()); // prompt user to input year of birth Console.Write("Enter the year you were born (1970): "); yearBorn = Convert.ToInt32(Console.ReadLine()); // prompt user to input height in inches Console.Write("Enter your height in inches (72): "); height = Convert.ToInt32(Console.ReadLine()); // prompt user to input weight in pounds Console.Write("Enter your weight in pounds (175): "); weight = Convert.ToInt32(Console.ReadLine()); // create HealthProfile object with attributes initialized to user input data HealthProfile profile1 = new HealthProfile(firstName, lastName, gender, monthBorn, dayBorn, yearBorn, height, weight); // output if info provided is accurate // age, month born, day born, year born, height, weight all need to be positive // month born and day born have upper limits - handled in HealthProfile // use AND (&&) because it's the same as nesting if statements if (profile1.Age > 0 && profile1.MonthBorn > 0 && profile1.DayBorn > 0 && profile1.YearBorn > 0 && profile1.Height > 0 && profile1.Weight > 0) { // user info Console.WriteLine("\nHealth Profile"); // display users first name, last name, gender, year of birth Console.WriteLine("\tName: {0} {1}", profile1.FirstName, profile1.LastName); Console.WriteLine("\tGender: {0}", profile1.Gender); Console.WriteLine("\tDate of Birth (mm/dd/yyyy): {0}/{1}/{2}", profile1.MonthBorn, profile1.DayBorn, profile1.YearBorn); // display users age Console.WriteLine("\tAge: {0} years", profile1.Age); // display users height and weight Console.WriteLine("\tHeight: {0} inches", profile1.Height); Console.WriteLine("\tWeight: {0} pounds", profile1.Weight); // display users max heart rate Console.WriteLine("\tMaximum Heart Rate: {0} beats per minute", profile1.MaxHeartRate); // display users target heart rate range Console.WriteLine("\tMinimum Target Heart Rate: {0} beats per minute", profile1.MaxTargetRate); Console.WriteLine("\tMaximum Target Heart Rate: {0} beats per minute", profile1.MinTargetRate); // display users BMI with BMI Values table Console.WriteLine("\tBody Mass Index (BMI) = {0}", profile1.BMI); Console.WriteLine("\nBMI VALUES"); Console.WriteLine("\tUnderweight: less than 18.5"); Console.WriteLine("\tNormal: between 18.5 and 24.9"); Console.WriteLine("\tOverweight: between 25 and 29.9"); Console.WriteLine("\tObese: 30 or greater"); } else { // inform user that there was an error with the inputs Console.WriteLine("\nOne or more of the values entered is incorrect."); Console.Write("Your health profile could not be completed "); Console.WriteLine("using the information provided."); } // end if else } // end Main
/*Crud operations * inside of * region * */ #region Crud Operations public HealthProfile Create(HealthProfile bmi) { _db.HealthProfile.Add(bmi); _db.SaveChanges(); return(bmi); }
public void Update(int id, HealthProfile bmi) { _db.Entry(bmi).State = EntityState.Modified; _db.SaveChanges(); }
internal Response SaveAndUpdateHealthProfile(HealthProfileModel healthProfile) { Response response = Response.Success; try { if (healthProfile.Id == 0) { HealthProfile HealthProfileDB = new HealthProfile(); HealthProfileDB.isSTakeantiBiotic = healthProfile.isSTakeantiBiotic; HealthProfileDB.isSuffreDiabetes = healthProfile.isSuffreDiabetes; HealthProfileDB.isSuffrePressure = healthProfile.isSuffrePressure; HealthProfileDB.isTakehaemophilia = healthProfile.isTakehaemophilia; HealthProfileDB.userId = healthProfile.userId; HealthProfileDB.DieaseNames = new List <DieaseName>(); for (int i = 0; i < healthProfile.dieaseNamesArray.Count; i++) { HealthProfileDB.DieaseNames.Add(new DieaseName() { Name = healthProfile.dieaseNamesArray[i] }); } checkUpContext.HealthProfiles.Add(HealthProfileDB); } else { HealthProfile HealthProfileDB = checkUpContext.HealthProfiles.Where(w => w.Id == healthProfile.Id).FirstOrDefault(); if (HealthProfileDB != null) { HealthProfileDB.isSTakeantiBiotic = healthProfile.isSTakeantiBiotic; HealthProfileDB.isSuffreDiabetes = healthProfile.isSuffreDiabetes; HealthProfileDB.isSuffrePressure = healthProfile.isSuffrePressure; HealthProfileDB.isTakehaemophilia = healthProfile.isTakehaemophilia; HealthProfileDB.userId = healthProfile.userId; if (HealthProfileDB.DieaseNames == null) { HealthProfileDB.DieaseNames = new List <DieaseName>(); } else { HealthProfileDB.DieaseNames.Clear(); } for (int i = 0; i < healthProfile.dieaseNamesArray.Count; i++) { HealthProfileDB.DieaseNames.Add(new DieaseName() { Name = healthProfile.dieaseNamesArray[i] }); } } } checkUpContext.SaveChanges(); } catch (Exception ex) { response = Response.Fail; } return(response); }
public void Update(int id, HealthProfile healthProfile) { //Update the health profile and save changes _db.Entry(healthProfile).State = EntityState.Modified; _db.SaveChanges(); }