예제 #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
     });
 }