public async Task <ActionResult> Delete(int id) { Dish dish = _dishRepo.Delete(id); await S3ImageService.RemoveFileFromS3(id); return(RedirectToAction(nameof(IndexPartner), dish)); }
public async Task <ActionResult> Create([FromForm] Dish dish) { var user = await _userManager.GetUserAsync(User); dish.PartnerId = user.Id; var createdDishId = _dishRepo.Save(dish); if (dish.File != null) { var fileName = System.IO.Path.GetFileName(dish.File.FileName); string fileLocation; if (System.IO.File.Exists(fileName)) { System.IO.File.Delete(fileName); } await using (var localFile = System.IO.File.OpenWrite(fileName)) { fileLocation = localFile.Name; await using var uploadedFile = dish.File.OpenReadStream(); uploadedFile.CopyTo(localFile); } await S3ImageService.UploadFileToS3(createdDishId, fileLocation); if (System.IO.File.Exists(fileName)) { System.IO.File.Delete(fileName); } } _dishRepo.Save(dish); return(RedirectToAction(nameof(IndexPartner))); }