private async Task <string> _saveToCdnAndGetUrl(AdminStoreItem newProductItem) { var fullProductUrl = StoreBlobLoader.CreateProudctItemImageUrl(newProductItem.Id, ImageSuportedFormats.Jpg); var format = StoreBlobLoader.GetFormat(ImageSuportedFormats.Jpg); var sbl = new StoreBlobLoader(); await sbl.SaveFromB64Async(newProductItem.Base64Images[0], fullProductUrl, format); return(fullProductUrl); }
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 async Task <JsonResult> UpdateProductItem(AdminStoreItem productItem) { var newAdminItem = await _dbProvider.ContextActionAsync(async connection => { var dbItem = _storeService.GetProductItem(connection, productItem.Id); dbItem.Trash = !productItem.Active; dbItem.Cost = (decimal)productItem.Price; dbItem.Property.TranslateText = productItem.L10N; if (productItem.Base64Images != null && productItem.Base64Images.Any() && !string.IsNullOrWhiteSpace(productItem.Base64Images[0])) { var fullProductUrl = await _saveToCdnAndGetUrl(productItem); dbItem.Property.ImgCollectionImg = new ImgCollectionField { Store = fullProductUrl, Chest = fullProductUrl }; } if (productItem.Properties != null) { switch (productItem.ProductType.Id) { case (byte)ProductTypeIds.Booster: var boosterProps = productItem.Properties .ToSerealizeString() .ToSpecificModel <List <string> >()[0] .ToSpecificModel <BoosterProductProperty>(); boosterProps.Duration = UnixTime.OneDayInSecond *productItem.Duration.Days; dbItem.Property.Property = boosterProps; break; } } var updatedData = _storeService.AddOrUpdateProductItem(connection, dbItem); return(new AdminStoreItem(updatedData, new AdminStoreData())); }); return(Json(newAdminItem)); }