Пример #1
0
        public MyPlaceDTO MyPlaceOperation(Token token, MyPlaceOperationParam param)
        {
            var securityInfo = SecurityManager.EnsureAuthentication(token);
            var service      = new MyPlaceService(Session, securityInfo, Configuration);

            return(service.MyPlaceOperation(param));
        }
Пример #2
0
 private void deleteSelectedItem()
 {
     if (SelectedItem != null && !SelectedItem.IsSystem && UIHelper.EnsurePremiumLicence() && BAMessageBox.AskYesNo(EnumLocalizer.Default.GetGUIString("MyPlacesView_QDeleteMyPlace"), SelectedItem.Name) == MessageBoxResult.Yes)
     {
         PleaseWait.Run(delegate(MethodParameters param)
         {
             try
             {
                 var param1       = new MyPlaceOperationParam();
                 param1.Operation = MyPlaceOperationType.Delete;
                 param1.MyPlaceId = SelectedItem.GlobalId;
                 ServiceManager.MyPlaceOperation(param1);
                 _myPlacesCache.Remove(SelectedItem.GlobalId);
                 UIHelper.BeginInvoke(() => NotifyOfPropertyChange(() => Items), Dispatcher);
             }
             catch (DeleteConstraintException ex)
             {
                 param.CloseProgressWindow();
                 UIHelper.BeginInvoke(() => ExceptionHandler.Default.Process(ex, EnumLocalizer.Default.GetGUIString("MyPlacesView_ErrDeleteMyPlace_IsInUse"), ErrorWindow.MessageBox), null);
             }
             catch (Exception ex)
             {
                 param.CloseProgressWindow();
                 UIHelper.BeginInvoke(() => ExceptionHandler.Default.Process(ex, EnumLocalizer.Default.GetGUIString("MyPlacesView_ErrDeleteMyPlace"), ErrorWindow.EMailReport), null);
             }
         });
     }
 }
Пример #3
0
        public MyPlaceDTO MyPlaceOperation(MyPlaceOperationParam param)
        {
            Log.WriteWarning("MyPlaceOperation:Username={0},place={1},operation={2}", SecurityInfo.SessionData.Profile.UserName, param.MyPlaceId, param.Operation);

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

            using (var tx = Session.BeginSaveTransaction())
            {
                var dbGym = Session.Get <MyPlace>(param.MyPlaceId);
                if (SecurityInfo.SessionData.Profile.GlobalId != dbGym.Profile.GlobalId)
                {
                    throw new CrossProfileOperationException("Cannot modify MyPlace for another user");
                }
                if (param.Operation == MyPlaceOperationType.Delete)
                {
                    if (dbGym.IsSystem)
                    {
                        throw new InvalidOperationException("Cannot delete system place");
                    }
                    if (dbGym.Entries.Count > 0)
                    {
                        throw new DeleteConstraintException("This Gym contains strenght training entries");
                    }
                    Session.Delete(dbGym);

                    if (dbGym.IsDefault)
                    {//we removed default place so now system place should be marked as default
                        var systemPlace = Session.QueryOver <MyPlace>().Where(x => x.Profile.GlobalId == SecurityInfo.SessionData.Profile.GlobalId && x.IsSystem).SingleOrDefault();
                        systemPlace.IsDefault = true;
                        Session.Update(systemPlace);
                    }
                    dbGym = null;
                }
                else
                {
                    setIsDefault(dbGym);
                }
                var dbProfile = Session.Get <Profile>(SecurityInfo.SessionData.Profile.GlobalId);
                dbProfile.DataInfo.MyPlaceHash = Guid.NewGuid();
                tx.Commit();

                if (dbGym != null)
                {
                    return(dbGym.Map <MyPlaceDTO>());
                }
                return(null);
            }
        }
        public void SetDefault_AnotherProfile()
        {
            var         Place   = CreateMyPlace("test", profiles[0]);
            var         profile = (ProfileDTO)profiles[1].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                var param       = new MyPlaceOperationParam();
                param.MyPlaceId = Place.GlobalId;
                param.Operation = MyPlaceOperationType.SetDefault;
                Service.MyPlaceOperation(data.Token, param);
            });
        }
        public void DeleteSystemMyPlace()
        {
            var         profile     = (ProfileDTO)profiles[0].Tag;
            SessionData data        = CreateNewSession(profile, ClientInformation);
            var         systemPlace = Session.QueryOver <MyPlace>().Where(x => x.Profile == profiles[0] && x.IsSystem).SingleOrDefault();

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                var param       = new MyPlaceOperationParam();
                param.MyPlaceId = systemPlace.GlobalId;
                param.Operation = MyPlaceOperationType.Delete;
                Service.MyPlaceOperation(data.Token, param);
            });
        }
        public void DeleteMyPlace_SecurityBug()
        {
            var Place = CreateMyPlace("test", profiles[0]);
            //we login as a different user
            var         profile = (ProfileDTO)profiles[1].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                var param       = new MyPlaceOperationParam();
                param.MyPlaceId = Place.GlobalId;
                param.Operation = MyPlaceOperationType.Delete;
                Service.MyPlaceOperation(data.Token, param);
            });
        }
        public void DeleteEmptyMyPlace()
        {
            var         Place   = CreateMyPlace("test", profiles[0]);
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                var param       = new MyPlaceOperationParam();
                param.MyPlaceId = Place.GlobalId;
                param.Operation = MyPlaceOperationType.Delete;
                Service.MyPlaceOperation(data.Token, param);
            });
            var item = Session.Get <MyPlace>(Place.GlobalId);

            Assert.AreEqual(null, item);
        }
        public void DeleteEmptyMyPlace_DataInfo()
        {
            var         Place   = CreateMyPlace("test", profiles[0]);
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);
            var         oldHash = profiles[0].DataInfo.MyPlaceHash;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                var param       = new MyPlaceOperationParam();
                param.MyPlaceId = Place.GlobalId;
                param.Operation = MyPlaceOperationType.Delete;
                Service.MyPlaceOperation(data.Token, param);
            });
            var dbProfile = Session.Get <Profile>(profile.GlobalId);

            Assert.AreNotEqual(oldHash, dbProfile.DataInfo.MyPlaceHash);
        }
        public void SetDefault()
        {
            var         Place   = CreateMyPlace("test", profiles[0]);
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                var param       = new MyPlaceOperationParam();
                param.MyPlaceId = Place.GlobalId;
                param.Operation = MyPlaceOperationType.SetDefault;
                Service.MyPlaceOperation(data.Token, param);
            });
            var dbPlace = Session.Get <MyPlace>(Place.GlobalId);

            Assert.IsTrue(dbPlace.IsDefault);
            var count = Session.QueryOver <MyPlace>().Where(x => x.Profile == profiles[0] && x.IsDefault).RowCount();

            Assert.AreEqual(1, count);
        }
Пример #10
0
 private void rbtnSetDefault_Click(object sender, RoutedEventArgs e)
 {
     if (SelectedItem != null && UIHelper.EnsurePremiumLicence())
     {
         PleaseWait.Run(delegate(MethodParameters param)
         {
             try
             {
                 var param1           = new MyPlaceOperationParam();
                 param1.Operation     = MyPlaceOperationType.SetDefault;
                 param1.MyPlaceId     = SelectedItem.GlobalId;
                 var result           = ServiceManager.MyPlaceOperation(param1);
                 var oldDefault       = _myPlacesCache.Items.Values.Where(x => x.IsDefault).Single();
                 oldDefault.IsDefault = false;
                 replace(SelectedItem, result);
             }
             catch (Exception ex)
             {
                 UIHelper.BeginInvoke(() => ExceptionHandler.Default.Process(ex, EnumLocalizer.Default.GetGUIString("MyPlacesView_ErrSetDefaultMyPlace"), ErrorWindow.EMailReport), null);
             }
         });
     }
 }
        public void DeleteMyPlaceWithEntries()
        {
            var         Place   = CreateMyPlace("test", profiles[0]);
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            var day = new TrainingDay(DateTime.Now.AddDays(-2));

            day.Profile = profiles[0];
            var entry = new StrengthTrainingEntry();

            entry.MyPlace = Place;
            day.AddEntry(entry);
            insertToDatabase(day);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                var param       = new MyPlaceOperationParam();
                param.MyPlaceId = Place.GlobalId;
                param.Operation = MyPlaceOperationType.Delete;
                Service.MyPlaceOperation(data.Token, param);
            });
        }
        public void DeleteDefaultMyPlace_SystemMyPlaceShouldBeDefaultAgain()
        {
            var Place = CreateMyPlace("test", profiles[0]);

            Place.IsDefault = true;
            insertToDatabase(Place);
            var systemPlace = Session.QueryOver <MyPlace>().Where(x => x.Profile == profiles[0] && x.IsSystem).SingleOrDefault();

            systemPlace.IsDefault = false;
            insertToDatabase(systemPlace);
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                var param       = new MyPlaceOperationParam();
                param.MyPlaceId = Place.GlobalId;
                param.Operation = MyPlaceOperationType.Delete;
                Service.MyPlaceOperation(data.Token, param);
            });
            systemPlace = Session.QueryOver <MyPlace>().Where(x => x.Profile == profiles[0] && x.IsSystem).SingleOrDefault();
            Assert.IsTrue(systemPlace.IsDefault);
        }
 public MyPlaceDTO MyPlaceOperation(Token token, MyPlaceOperationParam param)
 {
     return(exceptionHandling(token, () => InternalService.MyPlaceOperation(token, param)));
 }
Пример #14
0
 public static MyPlaceDTO MyPlaceOperation(MyPlaceOperationParam param)
 {
     return(exceptionHandling(() => Instance.MyPlaceOperation(Token, param)));
 }