public IActionResult Update(int id) { var boardgames = _assets.GetAllBoardgames(); var played = _assets.GetById(id); var model = new AssetPlayedUpdate() { Boardgames = boardgames, Descryption = played.Description }; return(View(model)); }
public IActionResult Update(AssetPlayedUpdate assetCreate) { if (ModelState.IsValid) { var webRoot = _env.WebRootPath; List <Image> images = new List <Image>(); if (assetCreate.imageUpload != null) { foreach (var file in assetCreate.imageUpload) { var filePath = Path.Combine(webRoot.ToString() + "\\images\\plays\\" + file.FileName); if (file.FileName.Length > 0) { using (var stream = new FileStream(filePath, FileMode.Create)) { file.CopyTo(stream); } images.Add(new Image { Url = "\\images\\plays\\" + file.FileName }); } } } var played = new Played() { Id = assetCreate.Id, Date = DateTime.Now, Description = assetCreate.Descryption, Boardgame = _assetBoardgame.GetById(assetCreate.BoardgameId) }; if (images.Count > 0) { played.Images = images; } _assets.Update(played); return(RedirectToAction("Detail", new { Id = played.Id })); } return(View()); }