public string ProcessUploadedFile(ProductDto dto, Product product) { string uniqueFileName = null; if (dto.Files != null && dto.Files.Count > 0) { foreach (var photo in dto.Files) { string uploadsFolder = Path.Combine(_env.WebRootPath, "multipleFileUpload"); uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { photo.CopyTo(fileStream); ExistingFilePath paths = new ExistingFilePath { Id = Guid.NewGuid(), FilePath = uniqueFileName, ProductId = product.Id }; _context.ExistingFilePath.Add(paths); } } } return(uniqueFileName); }
public async Task <Product> Update(ProductDto dto) { Product product = new Product(); ExistingFilePath file = new ExistingFilePath(); product.Id = dto.Id; product.Name = dto.Name; product.Description = dto.Description; product.Value = dto.Value; product.CreatedAt = dto.CreatedAt; product.ModifiedAt = DateTime.Now; if (dto.Files != null) { file.FilePath = ProcessUploadedFile(dto, product); } _context.Product.Update(product); await _context.SaveChangesAsync(); return(product); }