示例#1
0
        private TrainingPlan createPlan(Profile profile1, string name, PublishStatus status, TrainingPlanDifficult difficult, TrainingType type, params Exercise[] exercises)
        {
            var workoutPlan = new TrainingPlan();

            //workoutPlan.GlobalId = Guid.NewGuid();
            workoutPlan.Language     = "en";
            workoutPlan.Profile      = profile1;
            workoutPlan.Name         = name;
            workoutPlan.TrainingType = type;
            workoutPlan.Difficult    = difficult;
            workoutPlan.Author       = "test";

            workoutPlan.Status = status;
            if (status == PublishStatus.Published)
            {
                workoutPlan.PublishDate = DateTime.UtcNow;
            }
            BodyArchitect.Model.TrainingPlanDay day = new BodyArchitect.Model.TrainingPlanDay();
            day.Name = "day";
            workoutPlan.Days.Add(day);
            day.TrainingPlan     = workoutPlan;
            workoutPlan.Language = workoutPlan.Language;
            foreach (var exercise in exercises)
            {
                BodyArchitect.Model.TrainingPlanEntry entry = new BodyArchitect.Model.TrainingPlanEntry();
                entry.Exercise = exercise;
                day.Entries.Add(entry);
                entry.Day = day;
            }

            insertToDatabase(workoutPlan);
            workoutPlan.Tag = Mapper.Map <TrainingPlan, Service.V2.Model.TrainingPlans.TrainingPlan>(workoutPlan);
            return(workoutPlan);
        }
        private TrainingPlan createPlan(Profile profile1, string name, PublishStatus status, TrainingPlanDifficult difficult, TrainingType type, params Exercise[] exercises)
        {
            var plan = new BodyArchitect.Service.Model.TrainingPlans.TrainingPlan();

            var workoutPlan = new TrainingPlan();

            workoutPlan.GlobalId = Guid.NewGuid();
            workoutPlan.Language = "en";
            workoutPlan.Profile  = profile1;
            workoutPlan.Name     = plan.Name = name;
            plan.TrainingType    = (Service.Model.TrainingPlans.TrainingType)(workoutPlan.TrainingType = type);
            plan.Difficult       = (Service.Model.TrainingPlans.TrainingPlanDifficult)(workoutPlan.Difficult = difficult);
            workoutPlan.Author   = plan.Author = "test";

            workoutPlan.Status = status;
            if (status == PublishStatus.Published)
            {
                workoutPlan.PublishDate = DateTime.UtcNow;
            }
            TrainingPlanDay day = new TrainingPlanDay();

            day.Name = "day";
            plan.AddDay(day);
            plan.Language = workoutPlan.Language;
            foreach (var exercise in exercises)
            {
                TrainingPlanEntry entry = new TrainingPlanEntry();
                entry.ExerciseId = exercise.GlobalId;
                day.AddEntry(entry);
            }

            XmlSerializationTrainingPlanFormatter formatter = new XmlSerializationTrainingPlanFormatter();

            workoutPlan.PlanContent = formatter.ToXml(plan).ToString();

            Session.Save(workoutPlan);
            workoutPlan.Tag = Mapper.Map <TrainingPlan, WorkoutPlanDTO>(workoutPlan);
            return(workoutPlan);
        }