public AdminStoreItem(ProductStoreDataModel dbModel, AdminStoreData parendData) { Id = dbModel.Id; DateCreate = dbModel.Date.ToString("s"); NativeName = dbModel.Property.TranslateText.En.Name; Active = !dbModel.Trash; Properties = dbModel.Property.Property; ProductTypeIds tType; Enum.TryParse(dbModel.ProductTypeId.ToString(), out tType); ProductType = new NameIdInt((int)tType, tType.ToString()); ImagePath = dbModel.Property.ImgCollectionImg.Store; L10N = dbModel.Property.TranslateText; Currency = parendData.CurrencyList[tType == ProductTypeIds.Cc ? 0 : 1]; Price = (double)dbModel.Cost; Duration = parendData.DurationList[0]; if (tType == ProductTypeIds.Premium) { var premProps = ProductPropertyHelper.GetPremiumProperties(Properties); Duration = _getDaysFromSecond(premProps.Duration, parendData.DurationList); } else if (tType == ProductTypeIds.Booster) { var props = ProductPropertyHelper.GetBooserProperty(Properties); Duration = _getDaysFromSecond(props.Duration, parendData.DurationList); } }
public async Task <JsonResult> CreateNewProductItem(AdminStoreItem newProductItem) { // newProductItem.DateCreate = UnixTime.UtcNow(); var newAdminItem = await _dbProvider.ContextActionAsync(async connection => { var maxId = _storeService.GetMaxStoreId(connection); maxId++; newProductItem.Id = maxId; var fullProductUrl = await _saveToCdnAndGetUrl(newProductItem); object props = new { }; switch (newProductItem.ProductType.Id) { case (byte)ProductTypeIds.Premium: props = ProductPropertyHelper.CreatePremuiumProperties( UnixTime.OneDayInSecond *newProductItem.Duration.Days); break; case (byte)ProductTypeIds.Booster: var boosterProps = newProductItem.Properties .ToSerealizeString() .ToSpecificModel <List <string> >()[0] .ToSpecificModel <BoosterProductProperty>(); boosterProps.Duration = UnixTime.OneDayInSecond *newProductItem.Duration.Days; props = boosterProps; break; } var newProductStoreDataModel = new ProductStoreDataModel { Id = newProductItem.Id, Property = new ProductItemProperty { ImgCollectionImg = new ImgCollectionField { Store = fullProductUrl, Chest = fullProductUrl }, TranslateText = newProductItem.L10N, Property = props }, ProductTypeId = (byte)newProductItem.ProductType.Id, Trash = !newProductItem.Active, Cost = (decimal)newProductItem.Price, Date = DateTime.UtcNow, CurrencyCode = newProductItem.Currency.Name }; var newItem = _storeService.AddOrUpdateProductItem(connection, newProductStoreDataModel); return(new AdminStoreItem(newItem, new AdminStoreData())); }); return(Json(newAdminItem)); }
public ProductStoreDataModel AddOrUpdateProductItem(IDbConnection connection, ProductStoreDataModel productStoreDataModel) { ProductItems = null; return(_psCache.UpdateLocalItem(connection, _psRepo.AddOrUpdateeModel(connection, productStoreDataModel))); }