private string GetProductImageFileName(ProductRecord product, string productImageFileNameTemplate) { var imageFileName = string.Format(productImageFileNameTemplate, product.Id); var imagePhysicalPath = Path.Combine(Server.MapPath(ProductImagesRelativePath), imageFileName); return System.IO.File.Exists(imagePhysicalPath) ? imageFileName : null; }
private ProductImageSavingResult SaveProductBackImage(HttpPostedFileBase imageFile, ProductRecord product) { if (imageFile == null) { return null; } if (!IsImagePng(imageFile)) { _orchardServices.Notifier.Error( T("Back Image file should be *.png.", ProductImageWidth, ProductImageHeight)); return null; } using (var image = Image.FromStream(imageFile.InputStream, true, true)) { if (image.Width != ProductImageWidth || image.Height != ProductImageHeight) { _orchardServices.Notifier.Error( T("Back Image should be {0}x{1}.", ProductImageWidth, ProductImageHeight)); return null; } var imageFileName = string.Format(ProductImageBackFileNameTemplate, product.Id); var imagePhysicalPath = Path.Combine(Server.MapPath(ProductImagesRelativePath), imageFileName); image.Save(imagePhysicalPath, ImageFormat.Png); return new ProductImageSavingResult { Width = image.Width, Height = image.Height }; } }
private void FillProductViewModelWithGroups(ProductViewModel viewModel, ProductRecord product) { viewModel.ProductGroups = _productGroupRepository.Table .Where(g => g.ProdGroupCulture == cultureUsed) .OrderBy(g => g.Name) .Select(g => new ProductGroupItemViewModel { Id = g.Id, Name = g.Name }) .ToList(); var selectedProductGroupIds = _linkProductGroupRepository.Table .Where(it => it.ProductRecord == product) .Select(it => it.ProductGroupRecord.Id) .ToList(); viewModel.ProductGroups.ToList().ForEach(g => { if (selectedProductGroupIds.Contains(g.Id)) { g.Selected = true; } }); }
private void FillProductViewModelWithSizes(ProductViewModel viewModel, ProductRecord product) { viewModel.ProductSizes = _productSizeRepository.Table .Where(s => s.ProdSizeCulture == cultureUsed) .Fetch(s => s.SizeCodeRecord) .Select(s => new ProductSizeItemViewModel { Id = s.Id, LengthCm = s.LengthCm, WidthCm = s.WidthCm, SleeveCm = s.SleeveCm, LengthInch = s.LengthInch, WidthInch = s.WidthInch, SleeveInch = s.SleeveInch, SizeCodeId = s.SizeCodeRecord.Id, SizeCodeName = s.SizeCodeRecord.Name }) .ToList(); if (product == null) { return; } var selectedProductSizeIds = _linkProductSizeRepository.Table .Where(it => it.ProductRecord == product) //.Select(it => it.ProductSizeRecord.Id) .ToList(); viewModel.ProductSizes.ToList().ForEach(s => { if (selectedProductSizeIds.Exists(c => c.ProductSizeRecord.Id == s.Id)) { s.Selected = true; s.CostSize = selectedProductSizeIds.Where(c => c.ProductSizeRecord.Id == s.Id).First().SizeCost; } }); //var selectedProductSizeCost = _linkProductSizeRepository.Table // .Where(it => it.ProductRecord == product) // .Select(it => it.ProductSizId) // .ToList(); }
private void FillProductViewModelWithColours(ProductViewModel viewModel, ProductRecord product) { viewModel.ProductColours = _productColourRepository.Table .Where(c => c.ProdColorCulture == cultureUsed) .OrderBy(c => c.Name) .Select(c => new ProductColourItemViewModel { Id = c.Id, Name = c.Name, HexValue = c.Value }) .ToList(); if (product == null) { return; } var selectedProductColourIds = _linkProductColorRepository.Table .Where(it => it.ProductRecord == product) .Select(it => it.ProductColorRecord.Id) .ToList(); viewModel.ProductColours.ToList().ForEach(c => { if (selectedProductColourIds.Contains(c.Id)) { c.Selected = true; } }); viewModel.SelectedProductColours = _linkProductColorRepository.Table .Where(it => it.ProductRecord == product) .Fetch(it => it.ProductColorRecord) .Select(it => new ProductColourItemViewModel { Id = it.Id, ProductColourId = it.ProductColorRecord.Id, Name = it.ProductColorRecord.Name, HexValue = it.ProductColorRecord.Value, //BaseCost = it.ProductRecord.BaseCost }) .ToList(); }