public void PostProductInfo(ProduceInfo produceInfo) { Product product = new Product(); ProductPrice productPrice = new ProductPrice(); ProductAsset productAsset = new ProductAsset(); product.Name = produceInfo.Name; product.Manufacturer = produceInfo.Manufacturer; product.Brand = produceInfo.Brand; product.Description = produceInfo.Description; product.ProductCode = new Random().Next(65535); product.Status = "Y"; product.LastUpdated = DateTime.Now; db.Products.Add(product); db.SaveChanges(); int LastProductId = db.Products.OrderByDescending(p => p.Id).FirstOrDefault().Id; productPrice.Price = produceInfo.Price; productPrice.EffectiveFrom = DateTime.Now.ToShortDateString(); productPrice.LastUpdated = DateTime.Now; productPrice.ProductId_Id = LastProductId; productAsset.ImageUri = produceInfo.ImageUri; productAsset.Size = "100x100"; productAsset.Type = "Front"; productAsset.LastUpdated = DateTime.Now; productAsset.ProductId_Id = LastProductId; db.ProductPrices.Add(productPrice); db.ProductAssets.Add(productAsset); db.SaveChanges(); }
public ICollection <ProductAsset> BuildKaChingProductAssets(EntryContentBase entryContent) { if (entryContent.CommerceMediaCollection == null || entryContent.CommerceMediaCollection.Count == 0) { return(null); } var assets = new List <ProductAsset>(entryContent.CommerceMediaCollection.Count); // Load all media assets (except the first) in one go, for the particular catalog entry. // Skip the first item because it will already be exported as the main image on the product object. IDictionary <ContentReference, MediaData> mediaByContentLink = _contentLoader .GetItems( entryContent.CommerceMediaCollection .Skip(1) .Distinct(CommerceMediaComparer.Default) .Select(x => x.AssetLink), CultureInfo.InvariantCulture) .OfType <MediaData>() .ToDictionary(x => x.ContentLink); foreach (CommerceMedia commerceMedia in entryContent.CommerceMediaCollection.Skip(1)) { // Look up the referenced asset from the pre-loaded media assets. if (!mediaByContentLink.TryGetValue(commerceMedia.AssetLink, out MediaData mediaData)) { continue; } Uri absoluteUrl = GetAbsoluteUrl(mediaData.ContentLink); string mimeType; switch (mediaData.MimeType) { case "application/pdf": mimeType = "document/pdf"; break; case "image/jpeg": case "image/png": mimeType = mediaData.MimeType; break; default: continue; } var asset = new ProductAsset { MimeType = mimeType, Name = new L10nString(mediaData.Name), Url = absoluteUrl?.ToString() }; assets.Add(asset); } return(assets); }
public SingleUploaderModel(string id, string name, ProductAsset productAsset) { Id = id; Name = name; if (productAsset != null) { HaveAsset = true; AssetId = productAsset.ProductAssetId; Url = productAsset.FileUrl; } }
public virtual async Task UpdateAsync(ProductAsset entity, DateTime fromTime, DateTime?toTime, [NotNull] string currency, decimal?price) { if (await _repository.ExistConflictAsync(entity.Id, entity.StoreId, entity.ProductId, entity.ProductSkuId, entity.AssetId, entity.PeriodSchemeId, fromTime)) { throw new BusinessException(BookingErrorCodes.ConflictingProductAsset); } entity.Update(fromTime, toTime, currency, price); }
public void PutProductInfo(int id, ProduceInfo produceInfo) { Product product = db.Products.Find(id); ProductPrice productPrice = db.ProductPrices.Where(o => o.ProductId_Id == id).FirstOrDefault(); ProductAsset productAsset = db.ProductAssets.Where(o => o.ProductId_Id == id).FirstOrDefault(); product.Name = produceInfo.Name; product.Manufacturer = produceInfo.Manufacturer; product.Brand = produceInfo.Brand; product.Description = produceInfo.Description; product.LastUpdated = DateTime.Now; productPrice.Price = produceInfo.Price; productPrice.LastUpdated = DateTime.Now; productAsset.ImageUri = produceInfo.ImageUri; productAsset.LastUpdated = DateTime.Now; db.Entry(product).State = EntityState.Modified; db.Entry(productPrice).State = EntityState.Modified; db.Entry(productAsset).State = EntityState.Modified; db.SaveChanges(); }