コード例 #1
0
        private UchActiveItemView _activateChestItem(IDbConnection connection, UserChestDataModel chestItem, int userId)
        {
            UchActiveItemView result = null;

            if ((byte)ProductTypeIds.Account == chestItem.ProductTypeId)
            {
                // todo  реализовать
                return(result);
            }

            if ((byte)ProductTypeIds.Premium == chestItem.ProductTypeId)
            {
                return(_activatePremiunItem(connection, chestItem, userId));
            }


            if ((byte)ProductTypeIds.Booster == chestItem.ProductTypeId)
            {
                // todo  реализовать
                return(result);
            }

            if ((int)ProductTypeIds.Skins == chestItem.ProductTypeId)
            {
                // todo  реализовать
                return(result);
            }
            return(result);
        }
コード例 #2
0
 public UchNoActiveField(UserChestDataModel chestItem)
 {
     Id             = chestItem.Id;
     Activated      = chestItem.Activated;
     DateActivate   = chestItem.DateActivate;
     DateCreate     = chestItem.DateCreate;
     ProductTypeId  = chestItem.ProductTypeId;
     ProductStoreId = chestItem.ProductStoreId;
 }
コード例 #3
0
        private IList <UserChestDataModel> _createListUserChestDataModel(int userId, short productId, byte productTypeId, int transactionCcId, int quantity, int time)
        {
            var list = new List <UserChestDataModel>();

            for (var i = 0; i < quantity; i++)
            {
                var item = new UserChestDataModel
                {
                    UserId          = userId,
                    DateCreate      = time,
                    ProductTypeId   = productTypeId,
                    ProductStoreId  = productId,
                    Finished        = false,
                    Activated       = false,
                    TransactionsgId = transactionCcId
                };
                list.Add(item);
            }
            return(list);
        }
コード例 #4
0
 private bool _notActiveChestIsExist(IDbConnection connection, UserChestDataModel uch, int userId)
 {
     return(uch != null && uch.UserId == userId &&
            uch.Activated == false &&
            uch.Finished == false);
 }
コード例 #5
0
        private UchActiveItemView _activatePremiunItem(IDbConnection connection, UserChestDataModel chestItem, int userId)
        {
            var prod = _psCache.GetById(connection, chestItem.ProductStoreId, false);

            if (prod.Property == null)
            {
                throw new Exception(Error.InputDataIncorrect);
            }

            var pm = prod.Property.CreatePremuiumProperties();

            if (pm.Duration == 0)
            {
                throw new Exception(Error.PremiumDurationNotSet);
            }

            var premium = _premiumCache.GetById(connection, userId, true);

            if (premium == null)
            {
                throw new Exception(Error.PremiumNotExsist);
            }

            var duration     = (int)pm.Duration;
            var chestId      = chestItem.Id;
            var timeStampNow = UnixTime.UtcNow();
            var dateActivate = timeStampNow;
            var endTime      = 0;

            if (premium.EndTime < timeStampNow)
            {
                endTime = timeStampNow + duration;
            }
            else
            {
                endTime = premium.EndTime + duration;
            }
            premium.Data.Add(chestId, new UserPremiumtHistory(duration, dateActivate));
            premium.EndTime  = endTime;
            premium.Finished = false;
            premium          = _premiumCache.UpdateLocalItem(connection, _premiumRepo.AddOrUpdateeModel(connection, premium));


            //Запись в  таблицу user chest  об активации товара.



            var userChest = _userChestCache.GetById(connection, chestId, true);

            if (userChest == null)
            {
                throw new ArgumentNullException(Error.ChestNotExist, nameof(userChest));
            }
            userChest.DateActivate = dateActivate;
            userChest.Activated    = true;
            _userChestCache.UpdateLocalItem(connection, _userChestRepo.AddOrUpdateeModel(connection, userChest));

            //=============

            var userPrems = _chestGetUserPremiums(connection, userId);
            var prem      = new UchActiveItemView(ProductTypeIds.Premium)
            {
                Data = new UchPremiumData
                {
                    Premium  = premium,
                    StoreIds = userPrems.Select(i => i.ProductStoreId).ToList()
                }
            };
            var premType  = _ptCache.GetById(connection, (byte)ProductTypeIds.Premium, false);
            var pProperty = premType.Property.GetPremiumProperties();

            pProperty.Duration = premium.EndTime - timeStampNow;
            if (pProperty.Duration < 0)
            {
                throw new NotImplementedException("pProperty.Duration<0");
            }

            prem.ProductItemProperty = new ProductItemProperty
            {
                ImgCollectionImg = premType.Property.ImgCollectionImg,
                Property         = pProperty,
                TranslateText    = premType.Property.TranslateText
            };
            return(prem);
        }