コード例 #1
0
 public int GetStoreGoodCount(Server.Model.Store.Store store, User user, Good good)
 {
     try
     {
         LogEventManager.Logger.Info(
             "GetStoreGoodCount(Server.Model.Store.Store store, User user, Good good) execution started.");
         var userStore = (from usrStore in Db.Set <UserPersonalStore>()
                          join store1 in Db.Set <Server.Model.Store.Store>() on usrStore.StoreId equals store1.Id
                          where usrStore.UserId == user.Id && usrStore.StoreId == store.Id
                          select store1).SingleOrDefault();
         if (userStore == null)
         {
             throw new ArgumentException("Store doesn't exist");
         }
         return(_repository.GetStoreGoodCount(userStore, good));
     }
     catch (Exception ex)
     {
         LogEventManager.Logger.Error(ex.Message, ex);
         throw;
     }
     finally
     {
         LogEventManager.Logger.Info("GetStoreGoodCount(Server.Model.Store.Store store, User user, Good good) execution ended.");
     }
 }
コード例 #2
0
 public void IncreaseGoodQuantity(Server.Model.Store.Store store, Good good, User user, int count = 1)
 {
     try
     {
         var userStore = (from usrStore in Db.Set <UserPersonalStore>()
                          join store1 in Db.Set <Server.Model.Store.Store>() on usrStore.StoreId equals store1.Id
                          where usrStore.UserId == user.Id && usrStore.StoreId == store.Id
                          select store1).SingleOrDefault(); if (userStore == null)
         {
             throw new ArgumentException("Store doesn't exist");
         }
         _repository.IncreaseGoodQuantity(userStore, good, count);
     }
     catch (Exception ex)
     {
         LogEventManager.Logger.Error(ex.Message, ex);
         throw;
     }
 }
コード例 #3
0
        public void AddGood(Server.Model.Store.Store store, Good good, User user, int count = 1)
        {
            try
            {
                var userStore = Db.Set <UserPersonalStore>().SingleOrDefault(it => it.StoreId == store.Id && it.UserId == user.Id);

#if net452
                using (var scope = new TransactionScope(
                           TransactionScopeOption.Required, new TransactionOptions
                {
                    IsolationLevel = IsolationLevel.ReadCommitted,
                    Timeout = TimeSpan.FromMinutes(2)
                }))
                {
#endif
                var storeExists = store.Id != 0 || _repository.Exists(store, e => e.Id == store.Id);
                if (!storeExists)
                {
                    _repository.Save(store);
                }
                _repository.AddGood(store, good, count);

                if (userStore == null)
                {
                    Db.Set <UserPersonalStore>().Add(new UserPersonalStore
                    {
                        IsActive = true,
                        StoreId  = store.Id,
                        UserId   = user.Id,
                    });
                }
                Db.SaveChanges();
#if net452
                scope.Complete();
            }
#endif
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex.Message, ex);
                throw;
            }
        }
コード例 #4
0
        public void DeactivateStore(Server.Model.Store.Store store, User user)
        {
            try
            {
                var userStore = Db.Set <UserPersonalStore>().SingleOrDefault(it => it.StoreId == store.Id && it.UserId == user.Id);

                if (userStore == null || !userStore.IsActive)
                {
                    return;
                }
                userStore.IsActive = false;
                Db.SaveChanges();
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex.Message, ex);
                throw;
            }
        }
コード例 #5
0
 public void RemoveGood(Server.Model.Store.Store store, Good good, User user)
 {
     try
     {
         var userStore = (from usrStore in Db.Set <UserPersonalStore>()
                          join store1 in Db.Set <Server.Model.Store.Store>() on usrStore.StoreId equals store1.Id
                          where usrStore.UserId == user.Id && usrStore.StoreId == store.Id
                          select store1).SingleOrDefault();
         if (userStore == null)
         {
             return;
         }
         _repository.RemoveGood(userStore, good);
     }
     catch (Exception ex)
     {
         LogEventManager.Logger.Error(ex.Message, ex);
         throw;
     }
 }
コード例 #6
0
 public Good GetGoodById(User user, Server.Model.Store.Store store, int goodId, GoodInitOptions options = GoodInitOptions.Default)
 {
     try
     {
         var userStore = (from usrStore in Db.Set <UserPersonalStore>()
                          join store1 in Db.Set <Server.Model.Store.Store>() on usrStore.StoreId equals store1.Id
                          where usrStore.UserId == user.Id && usrStore.StoreId == store.Id
                          select store1).SingleOrDefault();
         if (userStore == null)
         {
             return(null);
         }
         var storeGood = Db.Set <StoreGood>().SingleOrDefault(it => it.GoodId == goodId && it.StoreId == userStore.Id);
         return(storeGood == null ? null : _goodRepo.GetById(storeGood.GoodId, options));
     }
     catch (Exception ex)
     {
         LogEventManager.Logger.Error(ex.Message, ex);
         throw;
     }
 }
コード例 #7
0
        public void RemoveStore(Server.Model.Store.Store store, User user)
        {
            try
            {
#if net452
                using (var scope = new TransactionScope(
                           TransactionScopeOption.Required, new TransactionOptions
                {
                    IsolationLevel = IsolationLevel.ReadCommitted,
                    Timeout = TimeSpan.FromMinutes(2)
                }))
                {
#endif
                var userStore =
                    Db.Set <UserPersonalStore>()
                    .SingleOrDefault(it => it.StoreId == store.Id && it.UserId == user.Id);
                if (userStore == null)
                {
                    return;
                }
                var storeVictim = Db.Set <Server.Model.Store.Store>().SingleOrDefault(it => it.Id == store.Id);
                userStore.Store = null;
                Db.Set <UserPersonalStore>().Remove(userStore);
                Db.SaveChanges();
                _repository.Delete(storeVictim);
#if net452
                scope.Complete();
            }
#endif
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex.Message, ex);
                throw;
            }
        }
コード例 #8
0
        public void AddStore(Server.Model.Store.Store store, User user, IEnumerable <Tuple <Good, int> > goods = null)
        {
            try
            {
#if net452
                using (var scope = new TransactionScope(
                           TransactionScopeOption.Required, new TransactionOptions
                {
                    IsolationLevel = IsolationLevel.ReadCommitted,
                    Timeout = TimeSpan.FromMinutes(2)
                }))
                {
#endif
                var userStore =
                    Db.Set <UserPersonalStore>()
                    .SingleOrDefault(it => it.StoreId == store.Id && it.UserId == user.Id);

                if (userStore != null)
                {
                    return;
                }
                var persStore = new UserPersonalStore
                {
                    UserId   = user.Id,
                    IsActive = true
                };
                var existingStore = _repository.GetById(store.Id);
                if (existingStore == null)
                {
                    _repository.Save(store);
                    persStore.Store = store;
                }
                else
                {
                    persStore.StoreId = store.Id;
                }

                Db.Set <UserPersonalStore>().Add(persStore);
                Db.SaveChanges();
                if (goods == null)
                {
#if net452
                    scope.Complete();
#endif
                    return;
                }
                foreach (var good in goods)
                {
                    AddGood(store, good.Item1, user, good.Item2);
                }
#if net452
                scope.Complete();
            }
#endif
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex.Message, ex);
                throw;
            }
        }