public async Task <IActionResult> DownloadRecipe(string Id) { if (!await _cocktailServices.CheckIfCocktailExist(Id)) { _toast.AddErrorToastMessage($"Cocktail with Id: {Id} does not exist!"); return(RedirectToAction("ListCocktails", "Cocktails")); } try { var cocktailName = await _cocktailServices.GetCocktailNameById(Id); var cocktailRecepie = await _cocktailServices.GetCocktailRecipe(Id); var content = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(cocktailRecepie)); var contentType = "APPLICATION/octet-stream"; var fileName = $"{cocktailName}.txt"; return(File(content, contentType, fileName)); } catch (Exception ex) { _toast.AddErrorToastMessage(ex.Message); ViewBag.ErrorTitle = ""; return(View("Error")); } }