示例#1
0
        public IEnumerable <TrainingDTO> GetTrainings(int TPID, string userId, bool trainer)
        {
            IEnumerable <trainingProgramTraining> tp = null;

            if (trainer)
            {
                trainer tr = db.trainer.FirstOrDefault(x => x.ID == userId);
                tp = db.trainingProgramTraining.Where(x => x.trainingProgram_TPID == TPID && x.trainingProgram.trainer_TRID == tr.TRID);
            }
            else
            {
                customer            c   = db.customer.FirstOrDefault(x => x.ID == userId);
                trainingProgramDate tpd = db.trainingProgramDate.OrderByDescending(x => x.date).FirstOrDefault(x => x.customer_CID == c.CID);
                if (tpd != null)
                {
                    tp = db.trainingProgramTraining.Where(x => x.trainingProgram_TPID == TPID && tpd.trainingProgram_TPID == TPID);
                }
            }

            List <TrainingDTO> trainingList = new List <TrainingDTO>();

            if (tp != null)
            {
                foreach (trainingProgramTraining x in tp)
                {
                    var training = (from t in db.training
                                    where t.TID == x.training_TID
                                    select new TrainingDTO
                    {
                        TID = t.TID,
                        className = t.className,
                        numberOfSets = t.numberOfSets,
                        numberOfReps = t.numberOfReps,
                        exercise_EID = t.exercise_EID,
                        durationMin = t.durationMin,
                        restBetweenMin = t.restBetweenMin,
                        sunday = t.sunday,
                        monday = t.monday,
                        tuesday = t.tuesday,
                        wednesday = t.wednesday,
                        thursday = t.thursday,
                        friday = t.friday,
                        saturday = t.saturday,
                        timeOfDay = t.timeOfDay
                    }).FirstOrDefault();
                    var name = GetExerciseName(training.exercise_EID);
                    training.name = name;
                    trainingList.Add(training);
                }
            }

            return(trainingList);
        }
 public bool AddTrainingProgramDate(TrainingProgramDateDTO TrainingProgramDate)
 {
     try
     {
         DateTime d = DateTime.Now;
         var      g = new trainingProgramDate
         {
             customer_CID         = TrainingProgramDate.customer_CID,
             trainingProgram_TPID = TrainingProgramDate.trainingProgram_TPID,
             date = d
         };
         db.trainingProgramDate.Add(g);
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }