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

            return(service.SaveMyPlace(place));
        }
 public void Fill(MyPlaceDTO myPlace)
 {
     if (myPlace.Address == null)
     {
         myPlace.Address = new AddressDTO();
     }
     Object = myPlace;
 }
        public void SaveNewMyPlace_DefaultColor()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            var Place = new MyPlaceDTO();

            Place.Name  = "name";
            Place.Color = null;
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                Place = service.SaveMyPlace(data.Token, Place);
                Assert.AreEqual(Constants.DefaultColor, Place.Color);
            });
            var db = Session.Get <MyPlace>(Place.GlobalId);

            Assert.AreEqual(Constants.DefaultColor, db.Color);
        }
        public void SaveNewMyPlace_DataInfo()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);
            var         oldHash = profiles[0].DataInfo.MyPlaceHash;

            var Place = new MyPlaceDTO();

            Place.Name  = "name";
            Place.Color = System.Drawing.Color.Aqua.ToColorString();
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                service.SaveMyPlace(data.Token, Place);
            });
            var dbProfile = Session.Get <Profile>(profile.GlobalId);

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

            var Place = new MyPlaceDTO();

            Place.Name  = "name";
            Place.Color = System.Drawing.Color.Aqua.ToColorString();
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var res = service.SaveMyPlace(data.Token, Place);
                Assert.Greater(res.CreationDate, DateTime.MinValue);
                Assert.AreNotEqual(Guid.Empty, res.GlobalId);
                Assert.AreEqual(profile.GlobalId, res.ProfileId);
            });
            Assert.AreEqual(2, Session.QueryOver <MyPlace>().Where(x => x.Profile == profiles[0]).RowCount());
        }
Пример #6
0
        private void newItem()
        {
            if (!UIHelper.EnsurePremiumLicence())
            {
                return;
            }
            var dlg = new EditDomainObjectWindow();

            var ctrl = new usrMyPlaceDetails();

            dlg.SetControl(ctrl);
            var myPlace = new MyPlaceDTO();

            myPlace.Color = Color.LavenderBlush.ToColorString();
            ctrl.Fill(myPlace);
            if (dlg.ShowDialog() == true)
            {
                _myPlacesCache.Add(ctrl.MyPlace);
                NotifyOfPropertyChange(() => Items);
            }
        }
        public void SaveNewMyPlace_WithAddress()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            var Place = new MyPlaceDTO();

            Place.Name               = "name";
            Place.Color              = System.Drawing.Color.Aqua.ToColorString();
            Place.Address            = new AddressDTO();
            Place.Address.City       = "Miasto";
            Place.Address.Country    = "country";
            Place.Address.Address1   = "address1";
            Place.Address.Address2   = "address2";
            Place.Address.PostalCode = "12345";
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                Place = service.SaveMyPlace(data.Token, Place);
                Assert.IsNotNull(Place.Address);
            });
            Assert.AreEqual(1, Session.QueryOver <Address>().RowCount());
            Assert.IsNotNull(Session.Get <MyPlace>(Place.GlobalId).Address);
        }
Пример #8
0
 private void replace(MyPlaceDTO selected, MyPlaceDTO saved)
 {
     _myPlacesCache.Replace(selected, saved);
     SelectedItem = saved;
     NotifyOfPropertyChange(() => Items);
 }
Пример #9
0
        public MyPlaceDTO SaveMyPlace(MyPlaceDTO place)
        {
            Log.WriteWarning("SaveMyPlace:Username={0},place={1}", SecurityInfo.SessionData.Profile.UserName, place.GlobalId);

            if (!SecurityInfo.Licence.IsPremium)
            {
                throw new LicenceException("This feature is allowed for Premium account");
            }
            var db = place.Map <MyPlace>();

            using (var transactionScope = Session.BeginSaveTransaction())
            {
                Address oldAddress = null;
                Profile dbProfile  = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId);
                if (db.IsNew)
                {
                    db.CreationDate = Configuration.TimerService.UtcNow;
                }
                else
                {
                    var temp = Session.Get <MyPlace>(db.GlobalId);
                    if (temp != null)
                    {
                        if (dbProfile != temp.Profile)
                        {
                            throw new CrossProfileOperationException("Cannot modify MyPlace for another user");
                        }
                        if (temp.IsSystem != db.IsSystem)
                        {
                            throw new InvalidOperationException("Cannot change IsSystem property");
                        }
                        if (temp.IsDefault != db.IsDefault)
                        {//user changed IsDefault
                            throw new InvalidOperationException("Cannot change IsDefault property using this method. Use MyPlaceOperation instead");
                        }
                        oldAddress = temp.Address;
                    }
                }

                if (db.Address != null && db.Address.IsEmpty)
                {
                    Log.WriteVerbose("Address is empty.");
                    if (!db.Address.IsNew && (oldAddress == null || db.Address.GlobalId != oldAddress.GlobalId))
                    {
                        Log.WriteInfo("Delete Address from db");
                        Session.Delete(db.Address);
                    }
                    db.Address = null;
                }

                if (oldAddress != null && (db.Address == null || oldAddress.GlobalId != db.Address.GlobalId))
                {
                    Session.Delete(oldAddress);
                }
                if (string.IsNullOrEmpty(db.Color))
                {
                    db.Color = Constants.DefaultColor;
                }
                db.Profile = dbProfile;
                db         = Session.Merge(db);
                dbProfile.DataInfo.MyPlaceHash = Guid.NewGuid();
                transactionScope.Commit();
                return(db.Map <MyPlaceDTO>());
            }
        }
 public MyPlaceDTO SaveMyPlace(Token token, MyPlaceDTO myPlace)
 {
     return(exceptionHandling(token, () => InternalService.SaveMyPlace(token, myPlace)));
 }
Пример #11
0
 public static MyPlaceDTO SaveMyPlace(MyPlaceDTO myPlace)
 {
     return(exceptionHandling(() => Instance.SaveMyPlace(Token, myPlace)));
 }