kehati/Controllers/HomeController.cs

70 lines
2.2 KiB
C#

using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using kehati.Models.View;
using kehati.Database;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace kehati.Controllers;
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly ApplicationDbContext db;
public HomeController(ILogger<HomeController> logger,ApplicationDbContext context)
{
_logger = logger;
db = context;
}
public async Task<IActionResult> Index()
{
//memanggil data lokasi dari master DB Lokasi
ViewBag.lokasiHome = await db.Lokasi
.Include(x => x.LokasiFauna)
.Include(x => x.LokasiTumbuhan)
.OrderByDescending(l => l.MsLokasiId)
.Take(3)
.ToListAsync();
ViewBag.tumbuhanHome = await db.Tumbuhan
.OrderByDescending(l => l.MsTumbuhanId)
.Take(4)
.ToListAsync();
ViewBag.faunaHome = await db.Fauna
.OrderByDescending(l => l.MsFaunaId)
.Take(4)
.ToListAsync();
ViewBag.TotalLokasi = await db.Lokasi.CountAsync();
ViewBag.TotalTumbuhan = await db.Tumbuhan.CountAsync();
ViewBag.TotalFauna = await db.Fauna.CountAsync();
ViewBag.Total = (ViewBag.TotalTumbuhan+ViewBag.TotalFauna);
// var model = new HomeViewModel
// {
// Statistik = new StatistikHomeModel
// {
// TotalLocations = 10,
// TotalFlora = 50,
// TotalFauna = 30,
// TotalSpecies = 80
// },
// };
return View();
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}