public IActionResult Save(ArtistVM artist) { if (!ModelState.IsValid) { artist.Country = new SelectList(countryRepository.GetCountries(), "Id", "Name").ToList(); artist.Style = new SelectList(styleRepository.GetStyles(), "Id", "Name").ToList(); return(View("Add", artist)); } Artists a = new Artists(); a.Biography = artist.Biography; a.Born = artist.Born; a.CountryId = artist.CountryId; a.Died = artist.Died; a.Name = artist.Name; artistRepository.InsertArtist(a); artistRepository.Save(); foreach (var x in artist.StyleId) { ArtistMovements movements = new ArtistMovements(); movements.ArtistId = a.Id; movements.StyleId = x; artistmovementRepository.InsertArtistMovement(movements); } artistmovementRepository.Save(); return(RedirectToAction("Add", "Image", new { id = a.Id })); }
public IActionResult Edit(ArtistVM artist) { if (!ModelState.IsValid) { artist.Country = new SelectList(countryRepository.GetCountries(), "Id", "Name").ToList(); artist.Style = new SelectList(styleRepository.GetStyles(), "Id", "Name").ToList(); return(View("Edit", artist)); } Artists a = new Artists(); a.Id = artist.Id; a.Name = artist.Name; a.Biography = artist.Biography; a.Born = artist.Born; a.CountryId = artist.CountryId; a.Died = artist.Died; artistRepository.UpdateArtist(a); artistRepository.Save(); IEnumerable <ArtistMovements> list = artistmovementRepository.GetArtistMovementsByArtist(artist.Id); foreach (var x in list) { artistmovementRepository.DeleteArtistMovement(x); } artistmovementRepository.Save(); foreach (var x in artist.StyleId) { ArtistMovements movements = new ArtistMovements(); movements.ArtistId = artist.Id; movements.StyleId = x; artistmovementRepository.InsertArtistMovement(movements); } artistmovementRepository.Save(); return(RedirectToAction("Index")); }
public void DeleteArtistMovement(ArtistMovements artistMovements) { context.ArtistMovements.Remove(artistMovements); }
public void UpdateArtistMovement(ArtistMovements artistMovements) { context.Entry(artistMovements).State = EntityState.Modified; }
public void InsertArtistMovement(ArtistMovements artistMovements) { context.ArtistMovements.Add(artistMovements); }