public ProductVideo AddVideo(int productId, string fileName, BinaryReader videoData) { fileName = $"{productId}_{Path.GetFileName(fileName)}"; var fileToSave = _fileProvider.GetAbsolutePath("videos", Path.GetRandomFileName()); using (var file = File.Create(fileToSave)) { var bufferSize = 5000000; byte[] buffer; do { buffer = videoData.ReadBytes(bufferSize); file.Write(buffer, 0, buffer.Length); }while(buffer.Length == bufferSize); } var res = new ProductVideo { ProductId = productId, FilePath = fileToSave, VideoName = fileName, Linked = false }; _repository.Insert(res); return(res); }
private void LoadVideoById(int videoId) { ProductVideo pv = ProductVideoService.GetProductVideo(videoId); if (pv == null) { MsgErr("Video with this ID not exist"); return; } preview.InnerHtml = pv.PlayerCode; preview.Visible = true; txtName.Text = pv.Name; txtPlayerCode.Text = pv.PlayerCode; txtDescription.Text = pv.Description; txtSortOrder.Text = pv.VideoSortOrder.ToString(CultureInfo.InvariantCulture); }
private NopProduct FindLinked(string shortVideoLink, int?videoStreamPositionSec) { var videoLinks = _videoRepository.Table .Where(x => x.ShortLink == shortVideoLink) .OrderBy(x => x.FromSec).ToList(); ProductVideo productVideo = videoLinks.FirstOrDefault(); if (productVideo != null && videoStreamPositionSec.HasValue) { productVideo = videoLinks.FirstOrDefault(x => x.FromSec <= videoStreamPositionSec.Value && x.ToSec >= videoStreamPositionSec.Value); } if (productVideo == null) { return(null); } return(_productRepository.GetById(productVideo.ProductId)); }
public async Task <Guid?> CreateAsync(CreateUpdateProductModel model) { var brand = catalogContext.Brands.FirstOrDefault(x => x.SellerId == model.OrganisationId.Value && x.IsActive); if (brand == null) { throw new CustomException(this.productLocalizer.GetString("BrandNotFound"), (int)HttpStatusCode.NotFound); } var category = catalogContext.Categories.FirstOrDefault(x => x.Id == model.CategoryId && x.IsActive); if (category == null) { throw new CustomException(this.productLocalizer.GetString("CategoryNotFound"), (int)HttpStatusCode.NotFound); } var product = new Product { IsNew = model.IsNew, IsPublished = model.IsPublished, IsProtected = model.IsProtected, Sku = model.Sku, BrandId = brand.Id, CategoryId = category.Id, PrimaryProductId = model.PrimaryProductId }; await this.catalogContext.Products.AddAsync(product.FillCommonProperties()); var productTranslation = new ProductTranslation { Language = model.Language, Name = model.Name, Description = model.Description, FormData = model.FormData, ProductId = product.Id }; await this.catalogContext.ProductTranslations.AddAsync(productTranslation.FillCommonProperties()); foreach (var imageId in model.Images.OrEmptyIfNull()) { var productImage = new ProductImage { MediaId = imageId, ProductId = product.Id }; await this.catalogContext.ProductImages.AddAsync(productImage.FillCommonProperties()); } foreach (var videoId in model.Videos.OrEmptyIfNull()) { var productVideo = new ProductVideo { MediaId = videoId, ProductId = product.Id }; await this.catalogContext.ProductVideos.AddAsync(productVideo.FillCommonProperties()); } foreach (var fileId in model.Files.OrEmptyIfNull()) { var productFile = new ProductFile { MediaId = fileId, ProductId = product.Id }; await this.catalogContext.ProductFiles.AddAsync(productFile.FillCommonProperties()); } await this.catalogContext.SaveChangesAsync(); await this.productIndexingRepository.IndexAsync(product.Id); return(product.Id); }
public async Task <Guid?> UpdateAsync(CreateUpdateProductModel model) { var brand = catalogContext.Brands.FirstOrDefault(x => x.SellerId == model.OrganisationId.Value && x.IsActive); if (brand == null) { throw new CustomException(this.productLocalizer.GetString("BrandNotFound"), (int)HttpStatusCode.NotFound); } var category = catalogContext.Categories.FirstOrDefault(x => x.Id == model.CategoryId && x.IsActive); if (category == null) { throw new CustomException(this.productLocalizer.GetString("CategoryNotFound"), (int)HttpStatusCode.NotFound); } var product = await this.catalogContext.Products.FirstOrDefaultAsync(x => x.Id == model.Id && x.Brand.SellerId == model.OrganisationId && x.IsActive); if (product == null) { throw new CustomException(this.productLocalizer.GetString("ProductNotFound"), (int)HttpStatusCode.NotFound); } product.IsNew = model.IsNew; product.IsPublished = model.IsPublished; product.IsProtected = model.IsProtected; product.Sku = model.Sku; product.BrandId = brand.Id; product.CategoryId = category.Id; product.PrimaryProductId = model.PrimaryProductId; product.LastModifiedDate = DateTime.UtcNow; var productTranslation = await this.catalogContext.ProductTranslations.FirstOrDefaultAsync(x => x.ProductId == product.Id && x.Language == model.Language && x.IsActive); if (productTranslation != null) { productTranslation.Name = model.Name; productTranslation.Description = model.Description; productTranslation.FormData = model.FormData; } else { var newProductTranslation = new ProductTranslation { Language = model.Language, ProductId = product.Id, Name = model.Name, Description = model.Description, FormData = model.FormData }; this.catalogContext.ProductTranslations.Add(newProductTranslation.FillCommonProperties()); } var productImages = this.catalogContext.ProductImages.Where(x => x.ProductId == model.Id && x.IsActive); foreach (var productImage in productImages.OrEmptyIfNull()) { this.catalogContext.ProductImages.Remove(productImage); } foreach (var imageId in model.Images.OrEmptyIfNull()) { var productImage = new ProductImage { MediaId = imageId, ProductId = product.Id }; await this.catalogContext.ProductImages.AddAsync(productImage.FillCommonProperties()); } var productVideos = this.catalogContext.ProductVideos.Where(x => x.ProductId == model.Id && x.IsActive); foreach (var productVideo in productVideos.OrEmptyIfNull()) { this.catalogContext.ProductVideos.Remove(productVideo); } foreach (var videoId in model.Videos.OrEmptyIfNull()) { var productVideo = new ProductVideo { MediaId = videoId, ProductId = product.Id }; await this.catalogContext.ProductVideos.AddAsync(productVideo.FillCommonProperties()); } var productFiles = this.catalogContext.ProductFiles.Where(x => x.ProductId == model.Id && x.IsActive); foreach (var productFile in productFiles.OrEmptyIfNull()) { this.catalogContext.ProductFiles.Remove(productFile); } foreach (var fileId in model.Files.OrEmptyIfNull()) { var productFile = new ProductFile { MediaId = fileId, ProductId = product.Id }; await this.catalogContext.ProductFiles.AddAsync(productFile.FillCommonProperties()); } var message = new UpdatedProductIntegrationEvent { OrganisationId = model.OrganisationId, Language = model.Language, Username = model.Username, ProductId = model.Id, ProductName = model.Name, ProductSku = model.Sku }; this.eventBus.Publish(message); await this.catalogContext.SaveChangesAsync(); await this.productIndexingRepository.IndexAsync(product.Id); return(product.Id); }
public static ProductVideo ToEntity(this ProductVideoModel model, ProductVideo destination) { return(model.MapTo(destination)); }
public static ProductVideoModel ToModel(this ProductVideo entity) { return(entity.MapTo <ProductVideo, ProductVideoModel>()); }
public void UpdateProductVideo(ProductVideo productVideo) { _productVideoRepository.Update(productVideo); }
public void InsertProductVideo(ProductVideo productVideo) { _productVideoRepository.Insert(productVideo); }