private void startSupplementsCycle(MyTrainingOperationParam param, SupplementCycle dbCycle, Profile dbProfile, Guid supplementsCycleDefinitionId)
        {
            dbCycle.Profile = dbProfile;

            var dbCycleDefinition = dbCycle.SupplementsCycleDefinition = Session.QueryOver <SupplementCycleDefinition>().Where(x => x.GlobalId == supplementsCycleDefinitionId).Fetch(x => x.Weeks).Eager.Fetch(x => x.Weeks.First().Dosages).Eager.SingleOrDefault();
            var definitionDTO     = dbCycleDefinition.Map <SupplementCycleDefinitionDTO>();
            SupplementsCycleRepetiter repetiter = new SupplementsCycleRepetiter();
            var preparedCycleDefinition         = repetiter.Preapre(definitionDTO, dbCycle.TotalWeeks);

            dbCycleDefinition = preparedCycleDefinition.Map <SupplementCycleDefinition>();

            for (int i = 0; i < dbCycleDefinition.GetTotalDays(dbCycle.TotalWeeks); i++)
            {
                createEntryObject(param.MyTraining, i, dbProfile, dbCycle, () =>
                {
                    List <EntryObject> entries = new List <EntryObject>();
                    var dosages = getDayDosages(dbCycleDefinition, i, dbCycle);
                    if (dosages.Count == 0)
                    {
                        return(entries);
                    }
                    if (dosages.OfType <SupplementCycleMeasurement>().Count() > 0)
                    {
                        SizeEntry sizeEntry = new SizeEntry();
                        entries.Add(sizeEntry);
                    }
                    var supplementEntries = dosages.OfType <SupplementCycleDosage>().ToList();
                    if (supplementEntries.Count == 0)
                    {
                        return(entries);
                    }
                    SuplementsEntry entry = new SuplementsEntry();
                    foreach (var dosage in supplementEntries)
                    {
                        SuplementItem item = new SuplementItem();
                        entry.AddItem(item);
                        item.Name          = dosage.Name;
                        item.Time.TimeType = (TimeType)dosage.TimeType;
                        item.Suplement     = Session.Load
                                             <Suplement>(dosage.Supplement.GlobalId);
                        item.Dosage = dosage.Dosage;
                        if (dosage.DosageUnit == BodyArchitect.Model.DosageUnit.ON10KgWight)
                        {
                            item.Dosage = (dosage.Dosage * (dbCycle.Weight / 10M)).RoundToNearestHalf();
                        }
                        item.DosageType = (DosageType)dosage.DosageType;
                    }
                    entries.Add(entry);
                    return(entries);
                });
            }
        }
        public override void BuildDatabase()
        {
            using (var tx = Session.BeginTransaction())
            {
                profiles.Clear();
                profiles.Add(CreateProfile(Session, "test1"));
                profiles.Add(CreateProfile(Session, "test2"));
                profiles.Add(CreateProfile(Session, "test3"));
                profiles.Add(CreateProfile(Session, "test4"));

                profiles[0].Wymiary     = new Wymiary();
                profiles[0].Wymiary.Pas = 102;

                Session.SaveOrUpdate(profiles[0]);



                TrainingDay day = new TrainingDay(DateTime.Now);
                day.Profile = profiles[0];
                StrengthTrainingEntry strengthEntry = new StrengthTrainingEntry();
                StrengthTrainingItem  item          = new StrengthTrainingItem();
                strengthEntry.AddEntry(item);
                item.ExerciseId = Guid.NewGuid();
                Serie serie = new Serie("10x20");
                item.AddSerie(serie);
                day.AddEntry(strengthEntry);
                SizeEntry sizeEntry = new SizeEntry();
                sizeEntry.Wymiary        = new Wymiary();
                sizeEntry.Wymiary.Height = 100;
                day.AddEntry(sizeEntry);
                SuplementsEntry suplementsEntry = new SuplementsEntry();
                SuplementItem   suplementItem   = new SuplementItem();
                suplementItem.SuplementId = Guid.NewGuid();
                suplementItem.Name        = "fdgdfg";
                suplementsEntry.AddItem(suplementItem);
                day.AddEntry(suplementsEntry);
                BlogEntry blogEntry = new BlogEntry();
                day.AddEntry(blogEntry);
                A6WEntry a6WEntry = new A6WEntry();
                a6WEntry.DayNumber          = 1;
                a6WEntry.MyTraining         = new MyTraining();
                a6WEntry.MyTraining.Name    = "fdgdfg";
                a6WEntry.MyTraining.TypeId  = A6WEntry.EntryTypeId;
                a6WEntry.MyTraining.Profile = profiles[0];
                day.AddEntry(a6WEntry);
                Session.Save(day);

                BlogComment comment = new BlogComment();
                comment.BlogEntry = blogEntry;
                comment.Profile   = profiles[1];
                comment.Comment   = "fgdfgd";
                Session.Save(comment);
                comment           = new BlogComment();
                comment.BlogEntry = blogEntry;
                comment.Comment   = "fgdfgd";
                comment.Profile   = profiles[0];
                Session.Save(comment);

                Session.Update(blogEntry);

                Exercise exercise = new Exercise(Guid.NewGuid());
                exercise.Profile  = profiles[0];
                exercise.Name     = "Private";
                exercise.Shortcut = "PP";
                Session.Save(exercise);

                exercise             = new Exercise(Guid.NewGuid());
                exercise.Profile     = profiles[0];
                exercise.Name        = "Public";
                exercise.Shortcut    = "PP";
                exercise.Status      = PublishStatus.Published;
                exercise.PublishDate = DateTime.UtcNow;
                Session.Save(exercise);

                RatingUserValue exComment = new RatingUserValue();
                exComment.ProfileId     = profiles[1].Id;
                exComment.ShortComment  = "dffgdfgdf";
                exComment.Rating        = 2;
                exComment.RatedObjectId = exercise.GlobalId;
                Session.Save(exComment);

                exercise             = new Exercise(Guid.NewGuid());
                exercise.Profile     = profiles[1];
                exercise.Name        = "Public1";
                exercise.Shortcut    = "PP1";
                exercise.Status      = PublishStatus.Published;
                exercise.PublishDate = DateTime.UtcNow;
                Session.Save(exercise);

                exComment               = new RatingUserValue();
                exComment.ProfileId     = profiles[0].Id;
                exComment.ShortComment  = "dffgdfgdf";
                exComment.Rating        = 2;
                exComment.RatedObjectId = exercise.GlobalId;
                Session.Save(exComment);

                TrainingPlan plan = new TrainingPlan();
                plan.Profile     = profiles[0];
                plan.GlobalId    = Guid.NewGuid();
                plan.Language    = "pl";
                plan.Author      = "dfgdfg";
                plan.Name        = "dfgdfg";
                plan.PlanContent = "fgdgdfg";
                Session.Save(plan);

                plan             = new TrainingPlan();
                plan.Profile     = profiles[0];
                plan.Language    = "pl";
                plan.GlobalId    = Guid.NewGuid();
                plan.Author      = "dfgdfg";
                plan.Status      = PublishStatus.Published;
                plan.PublishDate = DateTime.UtcNow;
                plan.Name        = "dfgdfg";
                plan.PlanContent = "fgdgdfg";
                Session.Save(plan);

                exComment               = new RatingUserValue();
                exComment.ProfileId     = profiles[1].Id;
                exComment.ShortComment  = "dffgdfgdf";
                exComment.Rating        = 2;
                exComment.RatedObjectId = plan.GlobalId;
                Session.Save(exComment);

                plan             = new TrainingPlan();
                plan.Profile     = profiles[1];
                plan.Language    = "pl";
                plan.GlobalId    = Guid.NewGuid();
                plan.Author      = "dfgdfg";
                plan.Status      = PublishStatus.Published;
                plan.PublishDate = DateTime.UtcNow;
                plan.Name        = "dfgdfg";
                plan.PlanContent = "fgdgdfg";
                Session.Save(plan);

                exComment               = new RatingUserValue();
                exComment.ProfileId     = profiles[0].Id;
                exComment.ShortComment  = "dffgdfgdf";
                exComment.Rating        = 2;
                exComment.RatedObjectId = plan.GlobalId;
                Session.Save(plan);


                exComment               = new RatingUserValue();
                exComment.ProfileId     = profiles[1].Id;
                exComment.ShortComment  = "dffgdfgdf";
                exComment.Rating        = 2;
                exComment.RatedObjectId = plan.GlobalId;
                Session.Save(exComment);

                exComment               = new RatingUserValue();
                exComment.ProfileId     = profiles[0].Id;
                exComment.ShortComment  = "dffgdfgdf";
                exComment.Rating        = 2;
                exComment.RatedObjectId = plan.GlobalId;
                Session.Save(plan);

                Message msg = new Message();
                msg.Receiver = profiles[0];
                msg.Sender   = profiles[1];
                msg.Topic    = "dfgdfgdf";
                Session.Save(msg);
                msg          = new Message();
                msg.Receiver = profiles[1];
                msg.Sender   = profiles[0];
                msg.Topic    = "dfgdfgdf";
                Session.Save(msg);

                FriendInvitation invitation = new FriendInvitation();
                invitation.Invited    = profiles[0];
                invitation.Inviter    = profiles[2];
                invitation.CreateDate = DateTime.UtcNow;
                Session.Save(invitation);

                invitation            = new FriendInvitation();
                invitation.Invited    = profiles[3];
                invitation.Inviter    = profiles[0];
                invitation.CreateDate = DateTime.UtcNow;
                Session.Save(invitation);

                profiles[0].Friends.Add(profiles[1]);
                profiles[1].Friends.Add(profiles[0]);
                profiles[1].Statistics.FriendsCount = 1;

                profiles[0].FavoriteUsers.Add(profiles[1]);
                profiles[1].Statistics.FollowersCount = 1;
                profiles[0].FavoriteWorkoutPlans.Add(plan);

                profiles[2].FavoriteUsers.Add(profiles[0]);
                Session.Update(profiles[0]);
                Session.Update(profiles[1]);
                Session.Update(profiles[2]);
                tx.Commit();
            }
        }