Exemple #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);
        }
        public TrainingPlan FromXml(IStatelessSession session, string xmlContent)
        {
            try
            {
                TrainingPlan plan = new TrainingPlan();
                XDocument    xml  = XDocument.Parse(xmlContent);

                var trainingPlanElement = xml.Element("TrainingPlan");
                plan.Author   = readValue(trainingPlanElement, "Author");
                plan.Language = readValue(trainingPlanElement, "Language");
                //plan.BasedOnId = readGuid(trainingPlanElement, "BasedOnId");
                plan.Comment      = readValue(trainingPlanElement, "Comment");
                plan.CreationDate = readDateTime(trainingPlanElement, "CreationDate").Value;
                plan.Difficult    = readEnum <TrainingPlanDifficult>(trainingPlanElement, "Difficult");
                plan.Purpose      = readEnum <WorkoutPlanPurpose>(trainingPlanElement, "Purpose");
                plan.GlobalId     = readGuid(trainingPlanElement, "GlobalId").Value;
                //plan.ProfileId = readGuid(trainingPlanElement, "ProfileId").Value;
                plan.Name         = readValue(trainingPlanElement, "Name");
                plan.Url          = readValue(trainingPlanElement, "Url");
                plan.RestSeconds  = readInt(trainingPlanElement, "RestSeconds").Value;
                plan.TrainingType = readEnum <TrainingType>(trainingPlanElement, "TrainingType");
                int position = 0;
                foreach (var dayNode in trainingPlanElement.Element("Days").Descendants("Day"))
                {
                    TrainingPlanDay day = new TrainingPlanDay();
                    plan.Days.Add(day);
                    day.TrainingPlan = plan;
                    day.Position     = position;
                    day.GlobalId     = readGuid(dayNode, "GlobalId").Value;
                    day.Name         = readValue(dayNode, "Name");

                    readTrainingEntries(session, day, dayNode);

                    readSuperSets(day, dayNode);
                    position++;
                }

                return(plan);
            }
            catch (VerificationException)
            {
                throw;
            }
            catch (Exception)
            {
                throw new FormatException("Selected xml doesn't contain training plan or it is damaged");
            }
        }
        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);
        }