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 GetArtist(int id) { Artists a = artistRepository.GetArtistById(id); ArtistVM model = new ArtistVM() { Id = a.Id, Name = a.Name, Born = a.Born, Died = a.Died, CountryId = a.CountryId, Biography = a.Biography, }; IEnumerable <ArtistMovements> am = artistmovementRepository.GetArtistMovementsByArtist(a.Id); model.StyleId = new List <int>(); foreach (ArtistMovements x in am) { model.StyleId.Add(x.StyleId); } model.Country = new SelectList(countryRepository.GetCountries(), "Id", "Name").ToList(); model.Style = new SelectList(styleRepository.GetStyles(), "Id", "Name").ToList(); return(View("Edit", model)); }
public IActionResult Index(int page = 1) { IEnumerable <Artists> list = artistRepository.GetArtists(); List <ArtistVM> model = new List <ArtistVM>(); const int PageSize = 12; var count = list.Count(); if (page == 1) { list = list.Skip(0).Take(PageSize).ToList(); } else { list = list.Skip((page - 1) * PageSize).Take(PageSize).ToList(); } if (count <= PageSize) { ViewBag.MaxPage = 1; } else { if (count % PageSize == 0) { ViewBag.MaxPage = (count / PageSize); } else { ViewBag.MaxPage = (count / PageSize) + 1; } } ViewBag.Page = page; ViewBag.NextPage = page + 1; foreach (Artists x in list) { ArtistVM a = new ArtistVM(); a.Id = x.Id; a.Name = x.Name; a.Biography = x.Biography; a.Born = x.Born; a.Country = x.Country.Name; a.Died = x.Died; a.Image = imageRepository.GetArtistImage(x.Id); if (a.Image != null) { a.ImageId = a.Image.Id; } a.Images = imageRepository.GetArtistImages(x.Id); a.Artworks = new List <ArtworkVM>(); a.Styles = new List <string>(); model.Add(a); } return(View(model)); }
public IActionResult Add() { ArtistVM model = new ArtistVM(); model.Country = new SelectList(countryRepository.GetCountries(), "Id", "Name").ToList(); model.Style = new SelectList(styleRepository.GetStyles(), "Id", "Name").ToList(); return(View("Add", model)); }
public IActionResult Details(int id) { Artists a = artistRepository.GetArtistById(id); ArtistVM model = new ArtistVM(); model.Artworks = new List <ArtworkVM>(); model.Styles = new List <string>(); List <Artworks> artworks = artworkRepository.GetArtworksByArtist(a.Id); foreach (Artworks art in artworks) { ArtworkVM vm = new ArtworkVM(); vm.Id = art.Id; vm.Name = art.Name; vm.Artist = a.Name; vm.Image = imageRepository.GetArtworkImage(art.Id); vm.Museum = art.Museum.Name; if (vm.Image != null) { vm.ImageId = vm.Image.Id; } vm.Likes = likesRepository.GetLikes(a.Id); if (Autentification.GetLoggedUser(HttpContext) != null) { Clients c = clientRepository.GetClientByUserId(Autentification.GetLoggedUser(HttpContext).Id); vm.Liked = likesRepository.IsLiked(c.Id, a.Id); } else { vm.Liked = false; } model.Artworks.Add(vm); } model.Biography = a.Biography; model.Born = a.Born; model.Country = a.Country.Name; model.Died = a.Died; model.Id = a.Id; model.Image = imageRepository.GetArtistImage(a.Id); if (model.Image != null) { model.ImageId = model.Image.Id; } model.Images = imageRepository.GetArtistImages(a.Id); model.Name = a.Name; IEnumerable <ArtistMovements> movements = stylesRepository.GetArtistMovementsByArtist(a.Id); foreach (ArtistMovements am in movements) { string style = am.Style.Name; model.Styles.Add(style); } return(View("Details", model)); }
public ArtistVM GetArtist(int id) { var artist = _db.ApplicationArtist.Where(m => m.Id == id).FirstOrDefault(); var newArtist = new ArtistVM { Id = artist.Id, Name = artist.Name, Genre = artist.Genre, ImageUrl = artist.ImageUrl }; return(newArtist); }
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 ActionResult Add() { CreateAlbumVM album = new CreateAlbumVM(); album.ProducerList = new List <ProducerVM>(); album.ArtistList = new List <ArtistVM>(); album.Producers = new SelectList(db.Producers.ToList(), "Id", "Name"); album.Artists = new SelectList(db.Artists.ToList(), "Id", "Name"); ProducerVM producer = new ProducerVM { Name = "", Studio = "", DateOfBirth = DateTime.Now }; ArtistVM artist = new ArtistVM { BirthDate = DateTime.Now, Email = "" }; album.ProducerList.Add(producer); album.ArtistList.Add(artist); return(View(album)); }