예제 #1
0
        internal static void InsertUserExerciseTypeSelections(List <UserExerciseTypeSelection> userExerciseTypeSelectionList)
        {
            try
            {
                foreach (UserExerciseTypeSelection entity in userExerciseTypeSelectionList)
                {
                    entity.ExerciseTypeName = GetExerciseTypeName(entity.ExerciseTypeId);
                    entity.ExerciseName     = GetExerciseName(entity.ExerciseId);
                }
            }
            catch (Exception ex1)
            {
                throw ex1;
            }

            try
            {
                using (dbContext = new ClinicalAthletes.Core.Data.ClinicalAthletes())
                {
                    dbContext.UserExerciseTypeSelections.AddRange(userExerciseTypeSelectionList);
                    dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
 internal static void InsertPurchases(Purchase purchase)
 {
     using (dbContext = new ClinicalAthletes.Core.Data.ClinicalAthletes())
     {
         dbContext.Purchases.Add(purchase);
         dbContext.SaveChanges();
     }
 }
예제 #3
0
 internal static int InsertUserExercisePlanSelection(UserExercisePlanSelection userExercisePlanSelection)
 {
     try
     {
         using (dbContext = new ClinicalAthletes.Core.Data.ClinicalAthletes())
         {
             dbContext.UserExercisePlanSelections.Add(userExercisePlanSelection);
             dbContext.SaveChanges();
             return(userExercisePlanSelection.Id);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #4
0
 internal static void UpdatePlanStatus(int id, bool isActive)
 {
     try
     {
         using (dbContext = new ClinicalAthletes.Core.Data.ClinicalAthletes())
         {
             var result = dbContext.ExercisePlans.SingleOrDefault(p => p.Id == id);
             if (result != null)
             {
                 result.IsActive = isActive;
                 dbContext.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #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
        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);
        }