コード例 #1
0
ファイル: SKU.cs プロジェクト: girish360/EnigmaShop
        public async Task UpdateSKUPictures(IList <IFormFile> files, IHostingEnvironment environment)
        {
            // Add Pictures to server directory and create SKUPictures
            var uploads = Path.Combine(environment.WebRootPath, "uploads");

            if (files?.Count > 0)
            {
                foreach (var formFile in files)
                {
                    if (formFile.Length <= 0)
                    {
                        continue;
                    }
                    var    guid      = Guid.NewGuid();
                    var    extension = Path.GetExtension(formFile.FileName);
                    string fileName  = $"sku_picture_{guid.ToString()}{extension}";
                    var    imageUrl  = Path.Combine("/uploads/", fileName);

                    if (SKUPictures.Any(x => x.ImageUrl == imageUrl))
                    {
                        continue;                                               //if this image is already saved
                    }
                    using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                    {
                        await formFile.CopyToAsync(fileStream);
                    }
                    AddSKUPicture(imageUrl, 100);
                }
            }
        }
コード例 #2
0
ファイル: SKU.cs プロジェクト: girish360/EnigmaShop
 private void AddSKUPicture(string imageUrl, int sorting)
 {
     SKUPictures.Add(new SKUPicture
     {
         SKU      = this,
         ImageUrl = imageUrl,
         Sorting  = sorting
     });
 }