Esempio n. 1
0
        public IActionResult Progress()
        {
            WeightTrackerVM vm = new WeightTrackerVM();

            vm.User = authProvider.GetCurrentUser();
            Goal goal = goalDAL.GetCurrentGoal(vm.User.Id);

            vm.GoalWeight = goal.GoalWeight;
            if (vm.GoalWeight == 0)
            {
                TempData["message"] = "Please set a goal so you can begin tracking your weight!";
            }
            else
            {
                List <WeightTrackerVM> list = weightDAL.GetAllWeights(vm.User.Id);
                if (list.Count < 2)
                {
                    TempData["message2"] = "Please log two conescutive days to see your progress!";
                }
                else
                {
                    vm.CurrentWeight           = list[0].LoggedWeight;
                    vm.CurrentWeightDateLogged = list[0].DateLogged;
                    vm.PastWeight = list[1].LoggedWeight;
                    vm.CurrentWeightDateLogged = list[1].DateLogged;
                }
            }
            return(View(vm));
        }
Esempio n. 2
0
        public IActionResult LogWeight(WeightTrackerVM weight)
        {
            User user = authProvider.GetCurrentUser();

            weightDAL.LogWeight(user, weight.LoggedWeight);
            return(RedirectToAction("Progress"));
        }
Esempio n. 3
0
        /// <summary>
        /// Gets all weights logged by this user historically
        /// </summary>
        /// <param name="user">The user who needs their historical weight values</param>
        /// <returns>Dictionary containing dates and weight values</returns>
        public List <WeightTrackerVM> GetAllWeights(int id)
        {
            List <WeightTrackerVM> list = new List <WeightTrackerVM>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    string sql = "select top 2 * from Weight join goals as g on g.user_id = weight.user_id where weight.user_id = @id order by weight.id DESC;";

                    SqlCommand cmd = new SqlCommand(sql, conn);
                    cmd.Parameters.AddWithValue("@id", id);
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        WeightTrackerVM weight = new WeightTrackerVM();
                        weight.WeightLogId = Convert.ToInt32(reader["id"]);
                        //weight.User.Id = Convert.ToInt32(reader["weight.user_id"]);
                        weight.GoalWeight   = Convert.ToDouble(reader["goal_weight"]);
                        weight.DateLogged   = Convert.ToDateTime(reader["log_date"]);
                        weight.LoggedWeight = Convert.ToDouble(reader["logged_weight"]);
                        list.Add(weight);
                    }
                }
            }
            catch (SqlException)
            {
                throw;
            }
            return(list);
        }