public async Task <string> PersistAsync(string path, BreadFile file) { string fileName = GetFileName(file); CheckPath(path); path = Path.Combine(path, fileName); await File.WriteAllBytesAsync(path, file.Bytes); return(fileName); }
public async Task AddImageAsync(int id, BreadFile image) { BLL.Restaurant bllRestaurant = await restaurantRepository.GetAsync(id); string restaurantPath = Path.Combine(storageOptions.RestaurantUploadsAbsolutePath, bllRestaurant.Name); string imagePath = await uploadsHandler.PersistAsync(restaurantPath, image); bllRestaurant.ImagePath = Path.Combine(GetRestaurantUploadsUrl(), imagePath).Replace("\\", "/"); await restaurantRepository.UpdateAsync(bllRestaurant); }
public async Task AddImageAsync(int id, BreadFile image) { BLL.Product bllProduct = await productRepository.GetAsync(id); if (bllProduct == null) { return; } BLL.Restaurant bllRestaurant = await restaurantRepository.GetAsync(bllProduct.RestaurantId); string productsPath = Path.Combine(storageOptions.RestaurantUploadsAbsolutePath, bllRestaurant.Name, ProductsFolderName); string imagePath = await uploadsHandler.PersistAsync(productsPath, image); bllProduct.ImagePath = Path.Combine(GetRestaurantUploadsUrl(bllRestaurant.Name), imagePath).Replace("\\", "/"); await productRepository.UpdateAsync(bllProduct); }
private static string GetFileName(BreadFile file) { return(Guid.NewGuid().ToString() + file.Extension); }