コード例 #1
0
        public bool AddTrainings(string userId, string trainings, int TPID)
        {
            trainer         trainer         = db.trainer.FirstOrDefault(x => x.ID == userId);
            trainingProgram trainingProgram = db.trainingProgram.FirstOrDefault(x => x.TPID == TPID);

            if (trainer.TRID != trainingProgram.trainer_TRID)
            {
                return(false);
            }
            else
            {
                try
                {
                    List <int> TIDList       = new List <int>();
                    var        trainingArray = JsonConvert.DeserializeObject <List <TrainingDTO> >(trainings);
                    foreach (TrainingDTO x in trainingArray)
                    {
                        var t = new training
                        {
                            exercise_EID   = x.exercise_EID,
                            numberOfSets   = x.numberOfSets == null ? null : x.numberOfSets,
                            numberOfReps   = x.numberOfReps == null ? null : x.numberOfReps,
                            durationMin    = x.durationMin == null ? null : x.durationMin,
                            restBetweenMin = x.restBetweenMin == null ? null : x.restBetweenMin,
                            sunday         = x.sunday,
                            monday         = x.monday,
                            tuesday        = x.tuesday,
                            wednesday      = x.wednesday,
                            thursday       = x.thursday,
                            friday         = x.friday,
                            saturday       = x.saturday,
                            className      = x.className,
                            timeOfDay      = x.timeOfDay
                        };
                        db.training.Add(t);
                        db.SaveChanges();
                        TIDList.Add(t.TID);
                    }
                    foreach (int x in TIDList)
                    {
                        db.trainingProgramTraining.Add(new trainingProgramTraining {
                            trainingProgram_TPID = TPID, training_TID = x
                        });
                    }
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
コード例 #2
0
        public int AddTrainingProgram(string UserId, TrainingProgramDTO trainingProgram)
        {
            var trainer = (from x in db.trainer
                           where x.ID == UserId
                           select x).FirstOrDefault();
            var tp = new trainingProgram
            {
                name         = trainingProgram.name,
                trainer_TRID = trainer.TRID,
                difficulty   = trainingProgram.difficulty
            };

            db.trainingProgram.Add(tp);
            db.SaveChanges();
            return(tp.TPID);
        }
コード例 #3
0
        public TrainingProgramDTO GetCurrentTrainingProgramByCid(int id)
        {
            trainingProgram p         = new trainingProgram();
            var             currentTp = db.trainingProgramDate.OrderByDescending(x => x.date).FirstOrDefault(x => x.customer_CID == id);

            if (currentTp != null)
            {
                p = db.trainingProgram.FirstOrDefault(x => x.TPID == currentTp.trainingProgram_TPID);
            }

            var tp = new TrainingProgramDTO
            {
                TPID = p.TPID,
                name = p.name,
            };

            return(tp);
        }