Пример #1
0
        public List <ExercisePlan> GetExercisePlansByWorkoutPlanId(int WorkoutPlanId)
        {
            using (var connection = new SqlConnection(ConnectionString))
            {
                using (var command = new SqlCommand("GetExercisePlansByWorkoutPlanId", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;

                    List <ExercisePlan> exercisePlans = new List <ExercisePlan>();

                    SqlParameter parameter;
                    parameter = new SqlParameter
                    {
                        ParameterName = "@WorkoutPlanId",
                        SqlDbType     = SqlDbType.Int,
                        Direction     = ParameterDirection.Input,
                        SqlValue      = WorkoutPlanId
                    };
                    command.Parameters.Add(parameter);

                    command.Connection.Open();

                    using (var dataReader = command.ExecuteReader())
                    {
                        if (dataReader.HasRows)
                        {
                            while (dataReader.Read())
                            {
                                ExercisePlan exercisePlan = new ExercisePlan
                                {
                                    ExercisePlanId = dataReader.GetInt32("ExercisePlanId"),
                                    WorkoutPlanId  = dataReader.GetInt32("WorkoutPlanId"),
                                    Exercise       = GetExerciseById(dataReader.GetInt32("ExerciseId")),
                                    Type           = dataReader.GetString("Type"),
                                    Rest           = dataReader.GetInt32("Rest"),
                                    Tempo          = dataReader.IsDBNull("Tempo") ? null : dataReader.GetString("Tempo"),
                                    RPE            = dataReader.IsDBNull("RPE") ? null : (int?)dataReader.GetInt32("RPE"),
                                    Order          = dataReader.IsDBNull("Order") ? null : (int?)dataReader.GetInt32("Order"),
                                    HasSuperset    = dataReader.GetBoolean("HasSuperset"),
                                    SetPlans       = GetSetPlansByExercisePlanId(dataReader.GetInt32("ExercisePlanId"))
                                };
                                if (exercisePlan.HasSuperset)
                                {
                                    exercisePlan.SupersetExercise = GetSupersetExerciseByExercisePlanId(exercisePlan.ExercisePlanId);
                                }
                                exercisePlans.Add(exercisePlan);
                            }
                        }
                    }

                    return(exercisePlans);
                }
            }
        }
        public HttpResponseMessage ImportExcelData(ExercisePlan exercisePlan)
        {
            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.BadRequest);

            try
            {
                ClinicalAthelete.Services.DataService.Import(exercisePlan);
                result = new HttpResponseMessage(HttpStatusCode.OK);
            }
            catch (System.Exception ex)
            {
                result = new HttpResponseMessage(HttpStatusCode.BadRequest);
            }

            return(result);
        }
Пример #3
0
        private void PopulateAssignedExerciseData(ExercisePlan exercisePlan)
        {
            var allExercises          = db.Exercises;
            var exercisePlanExercises = new HashSet <int>(exercisePlan.Exercises.Select(c => c.ExerciseID));
            var viewModel             = new List <AssignedExerciseData>();

            foreach (var exercise in allExercises)
            {
                viewModel.Add(new AssignedExerciseData
                {
                    ExerciseID = exercise.ExerciseID,
                    Title      = exercise.Title,
                    Assigned   = exercisePlanExercises.Contains(exercise.ExerciseID)
                });
            }
            ViewBag.Exercises = viewModel;
        }
Пример #4
0
        private static IndivoExercisePlan CreateIndivoExercisePlan(string accountId, ExercisePlan plan, Demographics demo)
        {
            // Default values in case we can't retrieve demographics
            int age = 0;
            string gender = string.Empty;

            if (demo != null)
            {
                age = GetAgeFromBirthDate(demo.dateOfBirth);
                gender = demo.gender;

                // dummy data in case indivo cant connect
                if (String.IsNullOrEmpty(gender))
                    gender = "Female";
            }

            IndivoExercisePlan indivoPlan = new IndivoExercisePlan(plan, accountId, age, gender);
            return indivoPlan;
        }
Пример #5
0
        public static bool Import(ExercisePlan exercisePlan)
        {
            try
            {
                exercisePlan.EntryDate = DateTime.Now;
                exercisePlan.IsActive  = true;

                using (dbContext = new ClinicalAthletes.Core.Data.ClinicalAthletes())
                {
                    dbContext.ExercisePlans.Add(exercisePlan);
                    dbContext.SaveChanges();
                    exercisePlan.ExerciseTypes = ImportExcerciseTypesFromExcel(exercisePlan);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #6
0
        public int AddWorkoutExercise(int WorkoutId, ExercisePlan ExercisePlan, int?WorkoutExerciseId = null)
        {
            using (var connection = new SqlConnection(ConnectionString))
            {
                using (var command = new SqlCommand("AddWorkoutExercise", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;

                    SqlParameter parameter;
                    parameter = new SqlParameter
                    {
                        ParameterName = "@WorkoutId",
                        SqlDbType     = SqlDbType.Int,
                        Direction     = ParameterDirection.Input,
                        SqlValue      = WorkoutId
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter
                    {
                        ParameterName = "@ExerciseId",
                        SqlDbType     = SqlDbType.Int,
                        Direction     = ParameterDirection.Input,
                        SqlValue      = ExercisePlan.Exercise.ExerciseId
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter
                    {
                        ParameterName = "@Type",
                        SqlDbType     = SqlDbType.VarChar,
                        Direction     = ParameterDirection.Input,
                        SqlValue      = ExercisePlan.Type
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter
                    {
                        ParameterName = "@Rest",
                        SqlDbType     = SqlDbType.Int,
                        Direction     = ParameterDirection.Input,
                        SqlValue      = ExercisePlan.Rest
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter
                    {
                        ParameterName = "@Tempo",
                        SqlDbType     = SqlDbType.VarChar,
                        Direction     = ParameterDirection.Input,
                        SqlValue      = ExercisePlan.Tempo
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter
                    {
                        ParameterName = "@RPE",
                        SqlDbType     = SqlDbType.Int,
                        Direction     = ParameterDirection.Input,
                        SqlValue      = ExercisePlan.RPE
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter
                    {
                        ParameterName = "@Order",
                        SqlDbType     = SqlDbType.Int,
                        Direction     = ParameterDirection.Input,
                        SqlValue      = ExercisePlan.Order
                    };
                    command.Parameters.Add(parameter);

                    parameter = new SqlParameter
                    {
                        ParameterName = "@HasSuperset",
                        SqlDbType     = SqlDbType.Bit,
                        Direction     = ParameterDirection.Input,
                        SqlValue      = ExercisePlan.HasSuperset
                    };
                    command.Parameters.Add(parameter);

                    if (WorkoutExerciseId.HasValue)
                    {
                        parameter = new SqlParameter
                        {
                            ParameterName = "@SupersetId",
                            SqlDbType     = SqlDbType.Int,
                            Direction     = ParameterDirection.Input,
                            SqlValue      = WorkoutExerciseId
                        };
                        command.Parameters.Add(parameter);
                    }

                    command.Connection.Open();

                    int workoutExerciseId = (int)command.ExecuteScalar();

                    return(workoutExerciseId);
                }
            }
        }
Пример #7
0
 public IndivoExercisePlan(ExercisePlan plan, string accountId, int userAge, string userGender)
 {
     HydrateObject(plan, accountId, userAge, userGender);
 }
Пример #8
0
 private void HydrateObject(ExercisePlan plan, string accountId, int age, string gender)
 {
     this.Plan = plan;
     this.AccountID = accountId;
     this.Age = age;
     this.Gender = gender;
 }
Пример #9
0
        private Payment CreatePayment(APIContext apiContext, string redirectUrl, int exercisePlanId)
        {
            ExercisePlan exercisePlan = DataService.GetExercisePlan(exercisePlanId);

            var itemList = new ItemList()
            {
                items = new List <Item>()
            };

            itemList.items.Add(new Item()
            {
                name     = @"Clinical Athletes-" + exercisePlan.PlanName,
                currency = "USD",
                price    = exercisePlan.Price.ToString(),
                quantity = "1",
                sku      = "sku"
            });

            var payer = new Payer()
            {
                payment_method = "paypal"
            };

            // Configure Redirect Urls here with RedirectUrls object
            var redirUrls = new RedirectUrls()
            {
                cancel_url = redirectUrl,
                return_url = redirectUrl
            };

            // similar as we did for credit card, do here and create details object
            var details = new Details()
            {
                tax      = "0",
                shipping = "0",
                subtotal = exercisePlan.Price.ToString()
            };

            // similar as we did for credit card, do here and create amount object
            var amount = new Amount()
            {
                currency = "USD",
                total    = exercisePlan.Price.ToString(), // Total must be equal to sum of shipping, tax and subtotal.
                details  = details
            };

            var transactionList = new List <Transaction>();

            transactionList.Add(new Transaction()
            {
                description    = @"Clinical Athletes-" + exercisePlan.PlanName,
                invoice_number = GetRandomInvoiceNumber(),
                amount         = amount,
                item_list      = itemList
            });

            this.payment = new Payment()
            {
                intent        = "sale",
                payer         = payer,
                transactions  = transactionList,
                redirect_urls = redirUrls
            };

            // Create a payment using a APIContext
            return(this.payment.Create(apiContext));
        }
Пример #10
0
        public ExercisePlan GetExercisePlan(string accountId)
        {
            ExercisePlan plan = new ExercisePlan();

            //using this to dummy up exercise plans
            int groupNo = new Random().Next(0, 1);
            ExercisePlanExerciseGroup exerciseGroup = GetExerciseGroup(groupNo);

            plan.exerciseGroups.Add(exerciseGroup);

            ExercisePlanExerciseGroup exGroup2 = new ExercisePlanExerciseGroup();
            plan.exerciseGroups.Add(exGroup2);

            return plan;
        }
Пример #11
0
 public ActionResult Import(ExercisePlan exercisePlan)
 {
     exercisePlan.ExcelFilePath = Server.MapPath("~/ExcelFiles/" + exercisePlan.ExcelFilePath);
     DataService.Import(exercisePlan);
     return(RedirectToAction("Dashboard", new { id = "success" }));
 }
Пример #12
0
        private static ICollection <ExerciseType> ImportExcerciseTypesFromExcel(ExercisePlan exercisePlan)
        {
            List <ExerciseType> listExerciseType = new List <ExerciseType>();

            using (ExcelPackage xlPackage = new ExcelPackage(new System.IO.FileInfo(exercisePlan.ExcelFilePath)))
            {
                // get the first worksheet in the workbook
                ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets[1];

                var rowCnt = worksheet.Dimension.End.Row;
                var colCnt = worksheet.Dimension.End.Column;

                //1. Loop each column & get Exercise Type with its excercises
                for (int i = 1; i <= colCnt; i++)//starting from two since 1 will have WeightRequired.
                {
                    if (!string.IsNullOrEmpty(Convert.ToString(worksheet.Cells[2, i].Value)))
                    {
                        listExerciseType.Add(new ExerciseType
                        {
                            ExercisePlanId = exercisePlan.Id,
                            Name           = (string)worksheet.Cells[2, i].Value,//starting from two since 1 will have WeightRequired.
                            WeightRequired = GetWeightRequired(Convert.ToString(worksheet.Cells[1, i].Value)),
                            EntryDate      = DateTime.Now,
                        });
                    }
                }

                using (dbContext = new ClinicalAthletes.Core.Data.ClinicalAthletes())
                {
                    dbContext.ExerciseTypes.AddRange(listExerciseType);
                    dbContext.SaveChanges();
                }

                //2. Add Exercises to ExerciseType
                for (int c = 1; c <= colCnt; c++)
                {
                    List <Exercise> list = new List <Exercise>();
                    for (int r = 3; r <= rowCnt; r++)
                    {
                        string cellVal = (string)worksheet.Cells[r, c].Value;

                        if (!string.IsNullOrEmpty(cellVal))
                        {
                            list.Add(new Exercise
                            {
                                Name           = cellVal,
                                ExerciseTypeId = listExerciseType[c - 1].Id,
                                EntryDate      = DateTime.Now,
                                IsActive       = true
                            });
                        }
                    }

                    using (dbContext = new ClinicalAthletes.Core.Data.ClinicalAthletes())
                    {
                        dbContext.Exercises.AddRange(list);
                        dbContext.SaveChanges();
                    }
                }
            }

            return(listExerciseType);
        }