Beispiel #1
0
        private void rbtPublish_Click(object sender, RoutedEventArgs e)
        {
            if (!UIHelper.EnsurePremiumLicence())
            {
                return;
            }
            var definition = SelectedDefinition;

            //todo:change to better window
            PleaseWait.Run(delegate
            {
                try
                {
                    var param = new SupplementsCycleDefinitionOperationParam();
                    param.SupplementsCycleDefinitionId = definition.GlobalId;
                    param.Operation = SupplementsCycleDefinitionOperation.Publish;
                    var result      = ServiceManager.SupplementsCycleDefinitionOperation(param);
                    SupplementsCycleDefinitionsReposidory.Instance.Update(result);
                }
                catch (ProfileRankException ex)
                {
                    UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, string.Format("SupplementsCycleDefinitions_Publish_ErrProfileRank".TranslateSupple(), Portable.Constants.StrengthTrainingEntriesCount), ErrorWindow.MessageBox), Dispatcher);
                }
                catch (Exception ex)
                {
                    Dispatcher.BeginInvoke(new Action(() => ExceptionHandler.Default.Process(ex, "ErrCannotPublishSuppleDefinition".TranslateSupple(), ErrorWindow.EMailReport)));
                }
            });
        }
        public static bool RemoveFromFavorites(this SupplementCycleDefinitionDTO definition)
        {
            if (!CanRemoveFromFavorites(definition))
            {
                return(false);
            }
            //ServiceManager.WorkoutPlanFavoritesOperation(plan, FavoriteOperation.Remove);

            ServiceCommand command = new ServiceCommand(() =>
            {
                try
                {
                    var param = new SupplementsCycleDefinitionOperationParam();
                    param.SupplementsCycleDefinitionId = definition.GlobalId;
                    param.Operation = SupplementsCycleDefinitionOperation.RemoveFromFavorites;
                    ServiceManager.SupplementsCycleDefinitionOperation(param);
                }
                catch (ObjectIsNotFavoriteException)
                {
                }
                catch
                {
                    SupplementsCycleDefinitionsReposidory.Instance.Add(definition);
                    throw;
                }
            });

            ServicePool.Add(command);
            SupplementsCycleDefinitionsReposidory.Instance.Remove(definition.GlobalId);
            return(true);
        }
Beispiel #3
0
        private void deleteSelectedSupplementDefinition()
        {
            var plan = SelectedDefinition;

            if (plan == null || plan.Profile.GlobalId != UserContext.Current.CurrentProfile.GlobalId || !UIHelper.EnsurePremiumLicence())
            {
                return;
            }
            if (BAMessageBox.AskYesNo(SuplementsEntryStrings.Question_usrSupplementsCyclesView_DoYouWantToDeleteCycle) == MessageBoxResult.Yes)
            {
                ParentWindow.RunAsynchronousOperation(delegate
                {
                    var param = new SupplementsCycleDefinitionOperationParam();
                    param.SupplementsCycleDefinitionId = plan.GlobalId;
                    param.Operation = SupplementsCycleDefinitionOperation.Delete;
                    ServiceManager.SupplementsCycleDefinitionOperation(param);
                    SupplementsCycleDefinitionsReposidory.Instance.Remove(plan.GlobalId);
                    //WorkoutPlansReposidory.Instance.ClearCache();
                    //Dispatcher.Invoke(new Action(delegate
                    //{
                    //    Fill();

                    //}));
                }, asyncOperationStateChange);
                //try
                //{

                //}
                //catch (Exception ex)
                //{
                //    ExceptionHandler.Default.Process(ex, StrengthTrainingEntryStrings.ErrorDuringDeleteTrainingPlan, ErrorWindow.EMailReport);
                //}
            }
        }
        public SupplementCycleDefinitionDTO SupplementsCycleDefinitionOperation(SupplementsCycleDefinitionOperationParam param)
        {
            Log.WriteWarning("SupplementsCycleDefinitionOperation:Username={0},Operation={1},GlobalId={2}", SecurityInfo.SessionData.Profile.UserName, param.Operation, param.SupplementsCycleDefinitionId);
            SupplementCycleDefinitionDTO result = null;

            if (!SecurityInfo.Licence.IsPremium)
            {
                throw new LicenceException("This feature is allowed for Premium account");
            }

            using (var transactionScope = Session.BeginSaveTransaction())
            {
                Profile dbProfile = Session.Get <Profile>(SecurityInfo.SessionData.Profile.GlobalId);
                var     db        = Session.Get <SupplementCycleDefinition>(param.SupplementsCycleDefinitionId);
                if (param.Operation == Model.SupplementsCycleDefinitionOperation.Delete)
                {
                    if (db.Profile != dbProfile)
                    {
                        throw new CrossProfileOperationException("This definition doesn't belong to this user");
                    }
                    if (db.Status == PublishStatus.Published)
                    {
                        throw new PublishedObjectOperationException("Cannot delete published definition");
                    }
                    Session.Delete(db);
                }
                else if (param.Operation == Model.SupplementsCycleDefinitionOperation.AddToFavorites)
                {
                    if (db.Status == PublishStatus.Private || db.Profile == dbProfile)
                    {
                        throw new InvalidOperationException("Cannot add private cycle definition to favorites list");
                    }
                    if (dbProfile.FavoriteSupplementCycleDefinitions.Contains(db))
                    {
                        throw new ObjectIsFavoriteException("Cycle definition is in favorites list already");
                    }
                    dbProfile.FavoriteSupplementCycleDefinitions.Add(db);
                }
                else if (param.Operation == Model.SupplementsCycleDefinitionOperation.RemoveFromFavorites)
                {
                    if (dbProfile.FavoriteSupplementCycleDefinitions.Contains(db))
                    {
                        dbProfile.FavoriteSupplementCycleDefinitions.Remove(db);
                    }
                    else
                    {
                        throw new ObjectIsNotFavoriteException("Cycle definition is not in favorites list");
                    }
                }
                else
                {
                    db     = publishCycleDefinition(db, dbProfile);
                    result = db.Map <SupplementCycleDefinitionDTO>();
                }
                dbProfile.DataInfo.SupplementsCycleDefinitionHash = Guid.NewGuid();
                transactionScope.Commit();
                return(result);
            }
        }
        public void DeleteCycleDefinition_AnotherProfile()
        {
            var         supp     = CreateSupplement("ttt");
            var         def      = CreateSupplementsCycleDefinition("test", supp, profiles[0]);
            var         profile1 = (ProfileDTO)profiles[1].Tag;
            SessionData data     = CreateNewSession(profile1, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param       = new SupplementsCycleDefinitionOperationParam();
                param.Operation = SupplementsCycleDefinitionOperation.Delete;
                param.SupplementsCycleDefinitionId = def.GlobalId;
                service.SupplementsCycleDefinitionOperation(data.Token, param);
            });
        }
        public void Publish_AlreadyPublished()
        {
            var         supp     = CreateSupplement("ttt");
            var         def      = CreateSupplementsCycleDefinition("test", supp, profiles[0], PublishStatus.Published);
            var         profile1 = (ProfileDTO)profiles[0].Tag;
            SessionData data     = CreateNewSession(profile1, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                TimerService.UtcNow = DateTime.UtcNow.Date.AddDays(-1);
                var param           = new SupplementsCycleDefinitionOperationParam();
                param.Operation     = SupplementsCycleDefinitionOperation.Publish;
                param.SupplementsCycleDefinitionId = def.GlobalId;
                service.SupplementsCycleDefinitionOperation(data.Token, param);
            });
        }
        public void DeleteCycleDefinition_NotUsedInAnyPlaces()
        {
            var         supp     = CreateSupplement("ttt");
            var         def      = CreateSupplementsCycleDefinition("test", supp, profiles[0], PublishStatus.Private);
            var         profile1 = (ProfileDTO)profiles[0].Tag;
            SessionData data     = CreateNewSession(profile1, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param       = new SupplementsCycleDefinitionOperationParam();
                param.Operation = SupplementsCycleDefinitionOperation.Delete;
                param.SupplementsCycleDefinitionId = def.GlobalId;
                service.SupplementsCycleDefinitionOperation(data.Token, param);
            });

            Assert.AreEqual(0, Session.QueryOver <SupplementCycleDefinition>().RowCount());
            Assert.AreEqual(0, Session.QueryOver <SupplementCycleWeek>().RowCount());
            Assert.AreEqual(0, Session.QueryOver <SupplementCycleDosage>().RowCount());
        }
        public void Publish_NotEnoughSupplementEntries()
        {
            profiles[0].Statistics.SupplementEntriesCount = 20;
            insertToDatabase(profiles[0].Statistics);

            var         supp     = CreateSupplement("ttt");
            var         def      = CreateSupplementsCycleDefinition("test", supp, profiles[0], PublishStatus.Private);
            var         profile1 = (ProfileDTO)profiles[0].Tag;
            SessionData data     = CreateNewSession(profile1, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                TimerService.UtcNow = DateTime.UtcNow.Date.AddDays(-1);
                var param           = new SupplementsCycleDefinitionOperationParam();
                param.Operation     = SupplementsCycleDefinitionOperation.Publish;
                param.SupplementsCycleDefinitionId = def.GlobalId;
                service.SupplementsCycleDefinitionOperation(data.Token, param);
            });
        }
        public void AddToFavorites_AlreadyIsInFavorites()
        {
            var supp = CreateSupplement("ttt");
            var def  = CreateSupplementsCycleDefinition("test", supp, profiles[1]);

            profiles[0].FavoriteSupplementCycleDefinitions.Add(def);
            insertToDatabase(profiles[0]);

            var         profile1 = (ProfileDTO)profiles[0].Tag;
            SessionData data     = CreateNewSession(profile1, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param       = new SupplementsCycleDefinitionOperationParam();
                param.Operation = SupplementsCycleDefinitionOperation.AddToFavorites;
                param.SupplementsCycleDefinitionId = def.GlobalId;
                service.SupplementsCycleDefinitionOperation(data.Token, param);
            });
        }
        public void AddToFavorites()
        {
            var         supp     = CreateSupplement("ttt");
            var         def      = CreateSupplementsCycleDefinition("test", supp, profiles[1]);
            var         profile1 = (ProfileDTO)profiles[0].Tag;
            SessionData data     = CreateNewSession(profile1, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param       = new SupplementsCycleDefinitionOperationParam();
                param.Operation = SupplementsCycleDefinitionOperation.AddToFavorites;
                param.SupplementsCycleDefinitionId = def.GlobalId;
                service.SupplementsCycleDefinitionOperation(data.Token, param);
            });

            Assert.AreEqual(1, Session.QueryOver <SupplementCycleDefinition>().RowCount());
            var dbProfile = Session.Get <Profile>(profile1.GlobalId);

            Assert.AreEqual(1, dbProfile.FavoriteSupplementCycleDefinitions.Count);
        }
        public void Publish_Statistics()
        {
            var         supp     = CreateSupplement("ttt");
            var         def      = CreateSupplementsCycleDefinition("test", supp, profiles[0], PublishStatus.Private);
            var         profile1 = (ProfileDTO)profiles[0].Tag;
            SessionData data     = CreateNewSession(profile1, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                TimerService.UtcNow = DateTime.UtcNow.Date.AddDays(-1);
                var param           = new SupplementsCycleDefinitionOperationParam();
                param.Operation     = SupplementsCycleDefinitionOperation.Publish;
                param.SupplementsCycleDefinitionId = def.GlobalId;
                service.SupplementsCycleDefinitionOperation(data.Token, param);
            });

            var dbProfile = Session.Get <Profile>(profile1.GlobalId);

            Assert.AreEqual(1, dbProfile.Statistics.SupplementsDefinitionsCount);
        }
        public void AddToFavorites_DataInfo_Owner()
        {
            var supp     = CreateSupplement("ttt");
            var def      = CreateSupplementsCycleDefinition("test", supp, profiles[1]);
            var profile1 = (ProfileDTO)profiles[0].Tag;
            var oldHash  = profiles[0].DataInfo.SupplementsCycleDefinitionHash;

            SessionData data = CreateNewSession(profile1, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param       = new SupplementsCycleDefinitionOperationParam();
                param.Operation = SupplementsCycleDefinitionOperation.AddToFavorites;
                param.SupplementsCycleDefinitionId = def.GlobalId;
                service.SupplementsCycleDefinitionOperation(data.Token, param);
            });

            var dbProfile = Session.Get <Profile>(profiles[1].GlobalId);

            Assert.AreEqual(oldHash, dbProfile.DataInfo.SupplementsCycleDefinitionHash);
        }
        public void Publish()
        {
            var         supp     = CreateSupplement("ttt");
            var         def      = CreateSupplementsCycleDefinition("test", supp, profiles[0], PublishStatus.Private);
            var         profile1 = (ProfileDTO)profiles[0].Tag;
            SessionData data     = CreateNewSession(profile1, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                TimerService.UtcNow = DateTime.UtcNow.Date.AddDays(-1);
                var param           = new SupplementsCycleDefinitionOperationParam();
                param.Operation     = SupplementsCycleDefinitionOperation.Publish;
                param.SupplementsCycleDefinitionId = def.GlobalId;
                service.SupplementsCycleDefinitionOperation(data.Token, param);
            });

            var cycle = Session.QueryOver <SupplementCycleDefinition>().SingleOrDefault();

            Assert.AreEqual(PublishStatus.Published, cycle.Status);
            Assert.AreEqual(DateTime.UtcNow.Date.AddDays(-1), cycle.PublishDate);
        }
 public SupplementCycleDefinitionDTO SupplementsCycleDefinitionOperation(Token token, SupplementsCycleDefinitionOperationParam definition)
 {
     return(exceptionHandling(token, () => InternalService.SupplementsCycleDefinitionOperation(token, definition)));
 }
Beispiel #15
0
        public SupplementCycleDefinitionDTO SupplementsCycleDefinitionOperation(Token token, SupplementsCycleDefinitionOperationParam param)
        {
            var securityInfo = SecurityManager.EnsureAuthentication(token);
            var service      = new SupplementsEngineService(Session, securityInfo, Configuration);

            return(service.SupplementsCycleDefinitionOperation(param));
        }