Esempio n. 1
0
        public void UpdateState([NotNull] SqlGameficationState state)
        {
            using (var db = new ApplicationContext())
            {
                var oldState = db.GameficationStates.FirstOrDefault(x => x.UserId == state.UserId);
                if (oldState == null)
                {
                    db.GameficationStates.Add(state);
                }
                else
                {
                    oldState.Loyalty = state.Loyalty;
                    db.GameficationStates.Update(oldState);
                }

                db.SaveChanges();
            }
        }
Esempio n. 2
0
        private SqlGameficationState ProcessEvent([NotNull] SqlEvent @event, [CanBeNull] SqlGameficationState state)
        {
            if (state == null)
            {
                return new SqlGameficationState
                       {
                           Loyalty = DefaultDelta,
                           UserId  = @event.CitizenId,
                       }
            }
            ;

            return(new SqlGameficationState
            {
                Loyalty = state.Loyalty + DefaultDelta,
                UserId = state.UserId,
            });
        }
    }
        public void Test()
        {
            //using (var db = new ApplicationContext())
            //{
            //    db.ClearDatabase();
            //    db.EnsureDatabaseCreated();
            //}

            var storage       = new GameficationStateStorage();
            var expectedState = new SqlGameficationState
            {
                UserId  = 12,
                Loyalty = 100,
            };

            storage.UpdateState(expectedState);

            var actualState = storage.TryGetState(12);

            Assert.AreNotEqual(null, actualState);
            Assert.AreEqual(expectedState.UserId, actualState.UserId);
            Assert.AreEqual(expectedState.Loyalty, actualState.Loyalty);
        }