protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { using (FHmasterEntities db = new FHmasterEntities()) { //get the weight if already set foreach (UserWeight uw in db.UserWeights) { if (uw.userID == System.Web.HttpContext.Current.User.Identity.GetUserId()) { //Set the weight txtWeight.Text = uw.weight.ToString(); } } } } catch (Exception ex) { Server.Transfer("/error.aspx", true); } } }
protected void deleteAllWeight_Click(object sender, EventArgs e) { try { using (FHmasterEntities db = new FHmasterEntities()) { //Go through each userworkout foreach (UserWorkout uw in db.UserWorkouts) { if (uw.userID == System.Web.HttpContext.Current.User.Identity.GetUserId()) { int workoutID = uw.workoutID; //Get the workoutID //Get the userweightworkout UserWeightWorkout uww = (from objUWW in db.UserWeightWorkouts where objUWW.workoutID == workoutID select objUWW).FirstOrDefault(); if (uww != null) { db.UserWeightWorkouts.Remove(uww); //Remove the usercardioworkout db.UserWorkouts.Remove(uw); //Remove the parent userworkout } } } db.SaveChanges(); } loadGridViews(); } catch (Exception ex) { Server.Transfer("/error.aspx", true); } }
protected void btnSave_Click(object sender, EventArgs e) { try { //do insert or update using (FHmasterEntities db = new FHmasterEntities()) { Int32 workoutID = 0; UserWorkout objUW = new UserWorkout(); //populate the workout from the input form objUW.date = DateTime.Now; objUW.userID = System.Web.HttpContext.Current.User.Identity.GetUserId(); db.UserWorkouts.Add(objUW); //Get the new workoutID foreach (UserWorkout ex in db.UserWorkouts) { if (ex.userID == System.Web.HttpContext.Current.User.Identity.GetUserId()){ workoutID = ex.workoutID; } } //If it's a weights workout, add to the user weight workout table if (ddlWorkoutType.SelectedValue == "1") { UserWeightWorkout uww = new UserWeightWorkout(); uww.workoutID = workoutID; //The matching workoutID uww.reps = Int32.Parse(txtInfo.Text); //The number of reps uww.exerciseID = Int32.Parse(ddlExercise.SelectedValue); //The exercise selected db.UserWeightWorkouts.Add(uww); } //If it's a cardio workout, add to the user cardio workout table else if (ddlWorkoutType.SelectedValue == "2") { UserCardioWorkout ucw = new UserCardioWorkout(); ucw.workoutID = workoutID; //The matching workoutID ucw.duration = Int32.Parse(txtInfo.Text); //The duration of cardio ucw.exerciseID = Int32.Parse(ddlExercise.SelectedValue); //The exercise selected db.UserCardioWorkouts.Add(ucw); } //save and redirect db.SaveChanges(); Response.Redirect("Profile.aspx"); } } catch (Exception ex) { Server.Transfer("/error.aspx", true); } }
protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { using (FHmasterEntities db = new FHmasterEntities()) { //For each type of exercise foreach (ExerciseType et in db.ExerciseTypes) { //Add the exercise type to the workout dropdown ddlWorkoutType.Items.Add(new ListItem(et.name, et.exerciseTypeID.ToString())); } } } //Clear all the exercises in the dropdown (if any) ddlExercise.Items.Clear(); using (FHmasterEntities db = new FHmasterEntities()) { //If the user has selected weight workout if (ddlWorkoutType.SelectedValue == "1") { foreach (Exercises ex in db.Exercises1) { //If the exercise type is weights, add the exercise to the dropdown if (ex.exerciseTypeID == 1) ddlExercise.Items.Add(new ListItem(ex.name, ex.exerciseID.ToString())); } lblExerciseInfo.Text = "Reps: "; //Update the label } //If the user has selected cardio workout else if (ddlWorkoutType.SelectedValue == "2") { foreach (Exercises ex in db.Exercises1) { //If the exercise type is cardio, add the exercise to the dropdown if (ex.exerciseTypeID == 2) ddlExercise.Items.Add(new ListItem(ex.name, ex.exerciseID.ToString())); } lblExerciseInfo.Text = "Duration (Minutes): "; //Update the label } } } catch (Exception ex) { Server.Transfer("/error.aspx", true); } }
protected void btnSave_Click(object sender, EventArgs e) { try { //do insert or update using (FHmasterEntities db = new FHmasterEntities()) { UserWeight objUW = new UserWeight(); Int32 weightID = 0; //get the weight if already set foreach (UserWeight uw in db.UserWeights) { if (uw.userID == System.Web.HttpContext.Current.User.Identity.GetUserId()) { //Set the weightID objUW = uw; weightID = uw.weightID; } } //populate the weight from the input form objUW.weight = Decimal.Parse(txtWeight.Text); if (weightID == 0) { //add objUW.userID = System.Web.HttpContext.Current.User.Identity.GetUserId(); db.UserWeights.Add(objUW); } //save and redirect db.SaveChanges(); Response.Redirect("Profile.aspx"); } } catch (Exception ex) { Server.Transfer("/error.aspx", true); } }
protected void getCardioWorkouts() { try { using (FHmasterEntities db = new FHmasterEntities()) { String userID = System.Web.HttpContext.Current.User.Identity.GetUserId(); //Query and get the user's cardio workouts var workouts = (from uw in db.UserWorkouts join w in db.UserCardioWorkouts on uw.workoutID equals w.workoutID join e in db.Exercises1 on w.exerciseID equals e.exerciseID join u in db.AspNetUsers on uw.userID equals u.Id where uw.userID == userID select new { uw.workoutID, e.name, w.duration, uw.date }); //Grab the ID, exercise name, duration, and date //Bind the results to the gridview grdCardioWorkouts.DataSource = workouts.ToList(); grdCardioWorkouts.DataBind(); } } catch (Exception ex) { Server.Transfer("/error.aspx", true); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>(); lblusername.Text = HttpContext.Current.User.Identity.Name; //Print the user's username lblemail.Text = manager.GetEmail(User.Identity.GetUserId()); //Print the user's email //Get the weight if set using (FHmasterEntities db = new FHmasterEntities()) { //get the weight if already set foreach (UserWeight uw in db.UserWeights) { if (uw.userID == System.Web.HttpContext.Current.User.Identity.GetUserId()) { //Set the weight lblweight.Text = "Weight: " + uw.weight.ToString(); } } } //Populate the gridview loadGridViews(); } catch (Exception ex) { Server.Transfer("/error.aspx", true); } } }
protected void grdUserWeightWorkout_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { //Get the workoutID of the row clicked Int32 workoutID = Convert.ToInt32(grdWeightWorkouts.DataKeys[e.RowIndex].Values["workoutID"]); using (FHmasterEntities db = new FHmasterEntities()) { //Grab the user workout and the matching user weight workout UserWorkout uw = (from objUW in db.UserWorkouts where objUW.workoutID == workoutID select objUW).FirstOrDefault(); UserWeightWorkout uww = (from objUWW in db.UserWeightWorkouts where objUWW.workoutID == workoutID select objUWW).FirstOrDefault(); db.UserWorkouts.Remove(uw); db.UserWeightWorkouts.Remove(uww); db.SaveChanges(); } loadGridViews(); } catch (Exception ex) { Server.Transfer("/error.aspx", true); } }