public IActionResult Index(int id) { ArtisteViewModel artisteViewModel = new ArtisteViewModel { Artiste = Startup.iartisteRepository.Find(id) }; artisteViewModel.TitresParAlbum = artisteViewModel.Artiste.Titres.GroupBy(t => t.UrlJaquette); return(View(artisteViewModel)); }
public IActionResult Index(string id) { var artisteVM = new ArtisteViewModel(); if (id.Contains("%2F")) { id = id.Replace("%2F", "/"); } artisteVM.Artist = _artisteRepository.Find(id); artisteVM.Albums = artisteVM.Artist.Titres.GroupBy(a => a.Album).Select(grp => grp.ToList()).ToList(); return(this.View(artisteVM)); }
public IActionResult Delete(int id) { try { Artiste artiste = _artisteRepository?.Find(id); _artiste = new ArtisteViewModel { IdArtiste = artiste.IdArtiste, NomArtiste = artiste.Nom }; return(this.View(nameof(ArtistesController.Delete), _artiste)); } catch (NullReferenceException e) { return(RedirectToAction(nameof(ArtistesController.Index), "Artistes", new { area = "Administration" })); } }
public ActionResult Create(ArtisteViewModel model) { if (ModelState.IsValid) { string uniqueFileName = null; // If the Photo property on the incoming model object is not null, then the user // has selected an image to upload. if (model.Photo != null) { // The image must be uploaded to the images folder in wwwroot // To get the path of the wwwroot folder we are using the inject // HostingEnvironment service provided by ASP.NET Core string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); // To make sure the file name is unique we are appending a new // GUID value and an underscore to the file name uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); // Use CopyTo() method provided by IFormFile interface to // copy the file to wwwroot/images folder model.Photo.CopyTo(new FileStream(filePath, FileMode.Create)); } Artiste artiste = new Artiste(); artiste.Id = 0; artiste.Name = model.Name; artiste.Image = uniqueFileName; this._artisteRepository.Add(artiste); return(RedirectToAction("Index")); } return(View()); }
public IViewComponentResult Invoke(ArtisteViewModel artiste) { return(View(artiste)); }