public IActionResult Index() { UserAccounts u = Autentification.GetLoggedUser(HttpContext); Administrators admin = null; Museums museum = null; if (u != null) { if (adminRepository.GetAdministrator(u.Id) != null) { admin = adminRepository.GetAdministrator(u.Id); } if (museumRepository.GetMuseumByAccId(u.Id) != null) { museum = museumRepository.GetMuseumByAccId(u.Id); } } if (admin != null) { return(RedirectToAction("Index", "Home", new { area = "Administrator" })); } else if (museum != null) { return(RedirectToAction("Index", "Home", new { area = "Moderator" })); } else { HomeVM model = new HomeVM(); List <Museums> list = museumRepository.GetTop3(); model.Museums = new List <MuseumVM>(); model.Artworks = new List <ArtworkVM>(); model.News = new List <NewsVM>(); List <Artworks> artworks = artworkRepository.GetTop6(); List <News> news = newsRepository.GetLatest(); foreach (Museums x in list) { MuseumVM m = new MuseumVM(); m.Id = x.Id; m.Description = x.Description; m.Image = imageRepository.GetMuseumImage(x.Id); m.Name = x.Name; if (m.Image != null) { m.ImageId = m.Image.Id; } model.Museums.Add(m); } foreach (Artworks x in artworks) { ArtworkVM a = new ArtworkVM(); a.Id = x.Id; a.Name = x.Name; a.Artist = x.Artist.Name; a.Museum = x.Museum.Name; a.Image = imageRepository.GetArtworkImage(x.Id); if (a.Image != null) { a.ImageId = a.Image.Id; } model.Artworks.Add(a); } foreach (News x in news) { NewsVM n = new NewsVM(); n.Id = x.Id; n.Date = x.Date; n.Image = imageRepository.GetNewsImage(x.Id); if (n.Image != null) { n.ImageId = n.Image.Id; } n.Museum = x.Museum.Name; n.Subtitle = x.SubTitle; n.Text = x.Text; n.Title = x.Title; model.News.Add(n); } return(View("Index", model)); } }