public StrengthProfileModel GetByUserId(int userId)
        {
            StrengthProfileModel strengthProfile = new StrengthProfileModel();

            using (SqlConnection con = new SqlConnection(connString))
            {
                SqlCommand cmd = new SqlCommand("dbo.StrengthProfile_SelectByUserId", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@UserId", userId);

                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    strengthProfile.Id               = (int)reader["Id"];
                    strengthProfile.UserId           = userId;
                    strengthProfile.Weight           = (decimal)reader["Weight"];
                    strengthProfile.BenchMax         = (int)reader["BenchMax"];
                    strengthProfile.DeadliftMax      = (int)reader["DeadliftMax"];
                    strengthProfile.SquatMax         = (int)reader["SquatMax"];
                    strengthProfile.ShoulderPressMax = (int)reader["ShoulderPressMax"];
                    strengthProfile.DateCreated      = Convert.ToDateTime(reader["DateCreated"]);
                    strengthProfile.DateModified     = Convert.ToDateTime(reader["DateModified"]);
                }
                con.Close();
            }
            return(strengthProfile);
        }
Beispiel #2
0
        public ActionResult <ItemResponse <StrengthProfileModel> > GetByUserId(int userId)
        {
            ItemResponse <StrengthProfileModel> response = null;
            ActionResult result = null;

            try
            {
                StrengthProfileModel strengthProfile = _strengthProfileService.GetByUserId(userId);

                if (strengthProfile.Id > 0)
                {
                    response      = new ItemResponse <StrengthProfileModel>();
                    response.Item = strengthProfile;
                    result        = Ok200(response);
                }
                else
                {
                    result = NotFound404(new ErrorResponse("User information not found."));
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                result = StatusCode(500, new ErrorResponse(ex.Message.ToString()));
            }
            return(result);
        }