public IActionResult Index() { int id = Autentification.GetLoggedUser(HttpContext).Id; Museums m = museumRepository.GetMuseumByAccId(id); List <Artworks> model = artworkRepository.GetArtworksByMuseum(m.Id); List <ArtworkInfoVM> list = new List <ArtworkInfoVM>(); foreach (Artworks x in model) { ArtworkInfoVM vm = new ArtworkInfoVM(); vm.Id = x.Id; vm.Artist = x.Artist.Name; vm.ArtistId = x.ArtistId; vm.Likes = likesRepository.GetLikes(x.Id); vm.Name = x.Name; vm.Image = imageRepository.GetArtworkImage(x.Id); if (vm.Image != null) { vm.ImageId = vm.Image.Id; } list.Add(vm); } ViewData["collections"] = collectionRepository.GetCollections(m.Id); return(View("Index", list)); }
public PartialViewResult Index(int id) { List <ArtworkCollections> model = artworkCollectionRepository.GetArtworkCollections(id); List <ArtworkInfoVM> list = new List <ArtworkInfoVM>(); foreach (ArtworkCollections x in model) { ArtworkInfoVM vm = new ArtworkInfoVM(); vm.Id = x.ArtworkId; vm.Artist = x.Artwork.Artist.Name; vm.ArtistId = x.Artwork.ArtistId; vm.Likes = likesRepository.GetLikes(x.Id); vm.Name = x.Artwork.Name; vm.Image = imageRepository.GetArtworkImage(x.ArtworkId); if (vm.Image != null) { vm.ImageId = vm.Image.Id; } list.Add(vm); } return(PartialView("Index", list)); }
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 IActionResult Index(int page = 1) { List <Artworks> list = artworkRepository.GetArtworks(); List <ArtworkVM> model = new List <ArtworkVM>(); 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 (Artworks x in list) { ArtworkVM vm = new ArtworkVM(); vm.Id = x.Id; vm.Artist = x.Artist.Name; vm.ArtworkType = x.ArtworkType.Name; vm.ArtworkTypeId = x.ArtworkTypeId; vm.CatalogueEntry = x.CatalogueEntry; vm.Country = x.Country.Name; vm.Image = imageRepository.GetArtworkImage(x.Id); if (vm.Image != null) { vm.ImageId = vm.Image.Id; } vm.Likes = likesRepository.GetLikes(x.Id); vm.Material = x.Material.Name; vm.Museum = x.Museum.Name; vm.MuseumId = x.MuseumId; vm.Name = x.Name; vm.Provenance = x.Provenance; vm.Style = x.Style.Name; if (Autentification.GetLoggedUser(HttpContext) != null) { Clients c = clientRepository.GetClientByUserId(Autentification.GetLoggedUser(HttpContext).Id); vm.Liked = likesRepository.IsLiked(c.Id, x.Id); } else { vm.Liked = false; } model.Add(vm); } return(View(model)); }